现在的位置: 首页 > 综合 > 正文

android Animation图片渐变动画 Demo

2013年09月07日 ⁄ 综合 ⁄ 共 2665字 ⁄ 字号 评论关闭

最终实现效果:


项目目录结构:


 

main.xml

Java代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.       
  7.     <ImageView   
  8.         android:id="@+id/iv_animation_logo"  
  9.         android:contentDescription="@string/animationContentDescription"  
  10.         android:layout_width="fill_parent"  
  11.         android:layout_height="fill_parent"  
  12.         android:src="@drawable/animation_logo"/>  
  13.   
  14. </RelativeLayout>  

 

AnimationDemoActivity.java

Java代码  收藏代码
  1. package com.royal.animationDemo;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.Window;  
  6. import android.view.WindowManager;  
  7. import android.view.animation.AlphaAnimation;  
  8. import android.view.animation.Animation;  
  9. import android.view.animation.Animation.AnimationListener;  
  10.   
  11. /** 
  12.  * 图片渐变动画 
  13.  */  
  14. public class AnimationDemoActivity extends Activity {  
  15.       
  16.     public static final int ANIMATION_TIME = 5000;  
  17.       
  18.     @Override  
  19.     public void onCreate(Bundle savedInstanceState) {  
  20.         super.onCreate(savedInstanceState);  
  21.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
  22.         // 去掉界面任务条  
  23.         this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  24.         setContentView(R.layout.main);  
  25.           
  26.         //图片渐变模糊度始终  
  27.         AlphaAnimation aa = new AlphaAnimation(0.1f,1.0f);  
  28.         //渐变时间  
  29.         aa.setDuration(ANIMATION_TIME);  
  30.         //展示图片渐变动画  
  31.         this.findViewById(R.id.iv_animation_logo).startAnimation(aa);  
  32.           
  33.         //渐变过程监听  
  34.         aa.setAnimationListener(new AnimationListener() {  
  35.               
  36.             /** 
  37.              * 动画开始时 
  38.              */  
  39.             @Override  
  40.             public void onAnimationStart(Animation animation) {  
  41.                 System.out.println("动画开始...");  
  42.             }  
  43.               
  44.             /** 
  45.              * 重复动画时 
  46.              */  
  47.             @Override  
  48.             public void onAnimationRepeat(Animation animation) {  
  49.                 System.out.println("动画重复...");  
  50.             }  
  51.               
  52.             /** 
  53.              * 动画结束时 
  54.              */  
  55.             @Override  
  56.             public void onAnimationEnd(Animation animation) {  
  57.                 System.out.println("动画结束...");  
  58.             }  
  59.         });  
  60.     }  
  61. }  

 

string.xml

Java代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.   
  4.     <string name="app_name">AnimationDemo</string>  
  5.     <string name="animationContentDescription">渐变图片动画描述</string>  
  6.   
  7. </resources>  

 

打印结果:


 

抱歉!评论已关闭.