android图片透明度跟缩放大小动画事件

概序 : 动画事件写在xml中,然后用AnimationUtils去加载动画事件,再监听动画结束事件,隐藏imageview。


1. player_double_click_animation.xml 动画文件

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <alpha
        android:duration="800"
        android:fromAlpha="0.1"
        android:toAlpha="1.0"/>

    <scale
        android:duration="800"
        android:fillAfter="false"
        android:fromXScale="0.2"
        android:fromYScale="0.2"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0"/>
</set>


alpha参数说明:

android:fromAlpha="1.0"   //这是表示动画一开始是完全不透明
android:toAlpha="0.0"        //这是表示动画结果时是完全透明
android:duration="500"    //这是动画的时间

scale参数说明:

float fromX 动画起始时 X坐标上的伸缩尺寸 
float toX 动画结束时 X坐标上的伸缩尺寸   
float fromY 动画起始时Y坐标上的伸缩尺寸  
float toY 动画结束时Y坐标上的伸缩尺寸  
int pivotXType 动画在X轴相对于物件位置类型  
float pivotXValue 动画相对于物件的X坐标的开始位置   
int pivotYType 动画在Y轴相对于物件位置类型   
float pivotYValue 动画相对于物件的Y坐标的开始位置  


2.布局文件test_aniamtion.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/click"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="点击我" />

    <ImageView
        android:id="@+id/like"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/icon_video_double_click"
        android:visibility="gone" />

</LinearLayout>


3.MainActivity.java

public class MainActivity extends Activity {
	private ImageView imageView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test_aniamtion);
		findViewById(R.id.click).setOnClickListener(listener);
		imageView=(ImageView) findViewById(R.id.like);
	}
	
	private OnClickListener listener=new OnClickListener() {
		@Override
		public void onClick(View v) {
			imageView.setVisibility(View.VISIBLE);
			//加载动画
			Animation animation=AnimationUtils.loadAnimation(MainActivity.this,R.anim.player_double_click_animation);
			imageView.startAnimation(animation);//开始动画
			animation.setAnimationListener(new AnimationListener(){
				@Override
				public void onAnimationStart(Animation animation) {}
				@Override
				public void onAnimationRepeat(Animation animation) {}
				@Override
				public void onAnimationEnd(Animation animation) {//动画结束
					imageView.setVisibility(View.GONE);
				}
			});
		}
	};
}


效果图如下:




点击下载

posted @ 2015-05-15 09:48  安辉  阅读(651)  评论(0编辑  收藏  举报