android Animation圖片漸變更畫 Demo


最終實現效果: java


項目目錄結構: android


 

main.xml app

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 ide

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>  

 

打印結果: this


相關文章
相關標籤/搜索