Android 動畫AlphaAnimation類方法

動畫的實現
1。實例化對象
AlphaAnimation anim = new AlphaAnimation(0.01f, 1.0f);
2。設置動畫持續時長(兩秒)
anim.setDuration(2000);
3。添加事件監聽
anim.setAnimationListener(new Animation.AnimationListener() {
            
    @Override
    public void onAnimationStart(Animation animation) {    
    }
            
    @Override
    public void onAnimationRepeat(Animation animation) {    
    }
            
    @Override
    public void onAnimationEnd(Animation animation) {
        //漸變動畫結束後,執行此方法,跳轉到主界面    
    }
});

4。爲控件綁定動畫效果
imageView.setAnimation(anim);

5。開始動畫

anim.start();


package com.example.animation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.widget.ImageView;


public class MainActivity extends Activity {
	private ImageView mldn=null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mldn=(ImageView)findViewById(R.id.mldn);
		mldn.setOnClickListener(new OnClickListenerImpl());
		
	}
	private class OnClickListenerImpl implements OnClickListener{

		@Override
		public void onClick(View v) {
			AnimationSet set=new AnimationSet(true);
			AlphaAnimation alp=new AlphaAnimation(1, 0);
			alp.setDuration(3000);
			set.addAnimation(alp);
			MainActivity.this.mldn.startAnimation(set);
			
		}
		
	}
		
	

		
	
}

原文博客 http://www.apkbus.com/blog-134260-54359.html


發佈了25 篇原創文章 · 獲贊 8 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章