android应用启动加载动画页面

1、当你打开一个应用程序时,会看到前面有一个加载动画页面,看看怎么来实现 

2、新建一个.xml 文件,添加一个ImageView 组件

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <ImageView   
  8.         android:id="@+id/welcome_img"  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="match_parent"  
  11.         />  
  12.   
  13. </RelativeLayout>

3、创建一个Activity

  1. package com.example.activity;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.view.animation.AlphaAnimation;  
  7. import android.view.animation.Animation;  
  8. import android.view.animation.Animation.AnimationListener;  
  9. import android.widget.ImageView;  
  10.   
  11. public class MainActivity extends Activity {  
  12.     private ImageView welcomeImg = null;  
  13.   
  14.     @Override  
  15.     protected void onCreate(Bundle savedInstanceState) {  
  16.         super.onCreate(savedInstanceState);  
  17.         setContentView(R.layout.activity_main);  
  18.         welcomeImg = (ImageView) this.findViewById(R.id.welcome_img);  
  19.         AlphaAnimation anima = new AlphaAnimation(0.3f, 1.0f);  
  20.         anima.setDuration(3000);// 设置动画显示时间  
  21.         welcomeImg.startAnimation(anima);  
  22.         anima.setAnimationListener(new AnimationImpl());  
  23.   
  24.     }  
  25.   
  26.     private class AnimationImpl implements AnimationListener {  
  27.   
  28.         @Override  
  29.         public void onAnimationStart(Animation animation) {  
  30.             welcomeImg.setBackgroundResource(R.drawable.welcome);  
  31.         }  
  32.   
  33.         @Override  
  34.         public void onAnimationEnd(Animation animation) {  
  35.             skip(); // 动画结束后跳转到别的页面  
  36.         }  
  37.   
  38.         @Override  
  39.         public void onAnimationRepeat(Animation animation) {  
  40.   
  41.         }  
  42.   
  43.     }  
  44.   
  45.     private void skip() {  
  46.         startActivity(new Intent(this, OtherActivity.class));  
  47.         finish();  
  48.     }  
  49. }  

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值