开启动画效果——渐隐渐现效果

启动某项程序时我们往往都能看到不同的“开机动画”,千变万化的动画也只不过是四种基本动画衍变美化而成的。

四种android动画效果:alpha   渐变透明度动画效果
                    scale  渐变尺寸伸缩动画效果
                   translate  画面转换位置移动动画效果
                   rotate  画面转移旋转动画效果

最简单的莫过于渐变透明效果,单单这一种就可完成渐隐渐现的动画效果(用于渐现渐隐的可以是整个欢迎页面也可以是欢迎页面里的一部分):

     1> 在res里新建anim文件夹用来盛放动画定义的动作文件:

[html]  view plain copy print ?
  1. <set xmlns:android="http://schemas.android.com/apk/res/android"  
  2.         android:interpolator="@android:anim/accelerate_interpolator">  
  3.         <alpha   
  4.             android:fromAlpha="0.0"  
  5.             android:toAlpha="1.0"  
  6.             android:duration="2000"/>  
  7.         <alpha   
  8.             android:fromAlpha="1.0"  
  9.             android:toAlpha="0.0"  
  10.             android:startOffset="3000"  
  11.             android:duration="3000"/>  
  12.       
  13. </set>  
fromalpha即开始的透明度,toalpha即结束时的透明度,duration为时间(单位毫秒)。

     2>定义布局文件(layout):

[html]  view plain copy print ?
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:gravity="center_vertical|center_horizontal"  
  6.     android:orientation="vertical" >  
  7.   
  8.     <ImageView  
  9.         android:id="@+id/welcom_logo"  
  10.         android:layout_width="fill_parent"  
  11.         android:layout_height="fill_parent"  
  12.         android:src="@drawable/welcome" />  
  13.   
  14. </LinearLayout>  

这里和以往没有任何不同,只需对要渐现渐隐的图片进行id标示。

    3>实现方法(Activity):

[java]  view plain copy print ?
  1. public class WelcomeActivity extends Activity implements AnimationListener {  
  2.     private ImageView imageView = null;  
  3.     private Animation alphaAnimation = null;  
  4.   
  5.     @Override  
  6.     public void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.         setContentView(R.layout.activity_welcome);  
  9.         imageView = (ImageView) findViewById(R.id.welcom_logo);  
  10.         alphaAnimation = AnimationUtils.loadAnimation(this,  
  11.                 R.anim.welcome_alpha);  
  12.         alphaAnimation.setFillEnabled(true);//启动Fill保持  
  13.         alphaAnimation.setFillAfter(true);//设置动画的最后一帧是保留在view上的  
  14.         imageView.setAnimation(alphaAnimation);  
  15.         alphaAnimation.setAnimationListener(this);  
  16.   
  17.     }  
  18.   
  19.     @Override  
  20.     public boolean onCreateOptionsMenu(Menu menu) {  
  21.         getMenuInflater().inflate(R.menu.activity_welcome, menu);  
  22.         return true;  
  23.     }  
  24.   
  25.     @Override  
  26.     public void onAnimationEnd(Animation animation) {  
  27.         //动画结束时结束欢迎页面并跳转到主页面  
  28.         Intent intent=new Intent(this,GroupActivity.class);  
  29.         startActivity(intent);  
  30.         this.finish();  
  31.   
  32.     }  
  33.   
  34.     @Override  
  35.     public void onAnimationRepeat(Animation animation) {  
  36.           
  37.   
  38.     }  
  39.   
  40.     @Override  
  41.     public void onAnimationStart(Animation animation) {  
  42.           
  43.   
  44.     }  
  45.     public boolean onKeyDown(int KeyCode,KeyEvent event){  
  46.         //在欢迎页面屏蔽BACK键  
  47.         if(KeyCode==KeyEvent.KEYCODE_BACK){  
  48.             return false;  
  49.         }  
  50.         return false;  
  51.           
  52.     }  
  53. }  

欢迎页面顾名思义只是装饰作用一闪而过不需要返回键进行操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值