赵雅智_splash启动界面

来源:互联网 发布:淘宝买家退货调包 编辑:程序博客网 时间:2024/04/29 07:09

项目需求

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

步骤

  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;}};};@Overrideprotected 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 {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}




0 0
原创粉丝点击