項目目錄結構: android
main.xml app
Java代碼
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
-
- <ImageView
- android:id="@+id/iv_animation_logo"
- android:contentDescription="@string/animationContentDescription"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:src="@drawable/animation_logo"/>
-
- </RelativeLayout>
AnimationDemoActivity.java ide
Java代碼
- package com.royal.animationDemo;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Window;
- import android.view.WindowManager;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.view.animation.Animation.AnimationListener;
-
- /**
- * 圖片漸變更畫
- */
- public class AnimationDemoActivity extends Activity {
-
- public static final int ANIMATION_TIME = 5000;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- // 去掉界面任務條
- this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.main);
-
- //圖片漸變模糊度始終
- AlphaAnimation aa = new AlphaAnimation(0.1f,1.0f);
- //漸變時間
- aa.setDuration(ANIMATION_TIME);
- //展現圖片漸變更畫
- this.findViewById(R.id.iv_animation_logo).startAnimation(aa);
-
- //漸變過程監聽
- aa.setAnimationListener(new AnimationListener() {
-
- /**
- * 動畫開始時
- */
- @Override
- public void onAnimationStart(Animation animation) {
- System.out.println("動畫開始...");
- }
-
- /**
- * 重複動畫時
- */
- @Override
- public void onAnimationRepeat(Animation animation) {
- System.out.println("動畫重複...");
- }
-
- /**
- * 動畫結束時
- */
- @Override
- public void onAnimationEnd(Animation animation) {
- System.out.println("動畫結束...");
- }
- });
- }
- }
string.xml 動畫
Java代碼
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
-
- <string name="app_name">AnimationDemo</string>
- <string name="animationContentDescription">漸變圖片動畫描述</string>
-
- </resources>
打印結果: this