赵雅智_splash启动界面

项目需求

设置初始化界面并实现界面跳转

步骤

  1. 启动界面主题设置为全屏
  2. 设置背景资源
  3. 实现开启动画和跳转

实现效果




具体代码

style.xml
<resources>
    <style name="AppBaseTheme" parent="android:Theme.Light">
 
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>
    <style name="theme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">?android:windowNoTitle</item>
    </style>

</resources>


splash.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"
    >  
    <item android:drawable="@drawable/a1" android:duration="1000"></item>  
    <item android:drawable="@drawable/a2" android:duration="1000"></item>  
    <item android:drawable="@drawable/a3" android:duration="1000"></item>  
    <item android:drawable="@drawable/a4" android:duration="1000"></item>  
    <item android:drawable="@drawable/a5" android:duration="1000"></item>  
    <item android:drawable="@drawable/a6" android:duration="1000"></item>  
</animation-list> 


activity_splash.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${packageName}.${activityClass}" >
 

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
    />

</RelativeLayout>


activty_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${packageName}.${activityClass}" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>


SplashActivity.java
package com.example.android_splash;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

public class SplashActivity extends Activity {
	private ImageView ivSplash;
	private AnimationDrawable animationDrawable;
	public static final int SPLASH = 1;
	public static final int DELAYANIM = 0;
	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case DELAYANIM:
				animationDrawable.start();
				break;
			case SPLASH:
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), MainActivity.class);
				startActivity(intent);
				finish();
				break;

			default:
				break;
			}
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);

		ivSplash = (ImageView) findViewById(R.id.imageView1);
		// 设置背景资源
		ivSplash.setBackgroundResource(R.drawable.splash);
		// 获取动画对象
		animationDrawable = (AnimationDrawable) ivSplash.getBackground();
		// 开启动画
		handler.sendEmptyMessageDelayed(DELAYANIM, 1000);
		// 跳转
		handler.sendEmptyMessageDelayed(SPLASH, 6000);

	}
}


MainActivity.java
package com.example.android_splash;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值