赵雅智_splash启动界面

项目需求

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

步骤

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

实现效果


赵雅智_splash启动界面_第1张图片

具体代码

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);
	}
}




你可能感兴趣的:(赵雅智_splash启动界面)