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

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


1. player_double_click_animation.xml 动画文件

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.     <alpha  
  4.         android:duration="800"  
  5.         android:fromAlpha="0.1"  
  6.         android:toAlpha="1.0"/>  
  7.   
  8.     <scale  
  9.         android:duration="800"  
  10.         android:fillAfter="false"  
  11.         android:fromXScale="0.2"  
  12.         android:fromYScale="0.2"  
  13.         android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
  14.         android:pivotX="50%"  
  15.         android:pivotY="50%"  
  16.         android:toXScale="1.0"  
  17.         android:toYScale="1.0"/>  
  18. </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

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <Button  
  8.         android:id="@+id/click"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:text="点击我" />  
  12.   
  13.     <ImageView  
  14.         android:id="@+id/like"  
  15.         android:layout_width="wrap_content"  
  16.         android:layout_height="wrap_content"  
  17.         android:layout_gravity="center"  
  18.         android:src="@drawable/icon_video_double_click"  
  19.         android:visibility="gone" />  
  20.   
  21. </LinearLayout>  


3.MainActivity.java

  1. public class MainActivity extends Activity {  
  2.     private ImageView imageView;  
  3.       
  4.     @Override  
  5.     protected void onCreate(Bundle savedInstanceState) {  
  6.         super.onCreate(savedInstanceState);  
  7.         setContentView(R.layout.test_aniamtion);  
  8.         findViewById(R.id.click).setOnClickListener(listener);  
  9.         imageView=(ImageView) findViewById(R.id.like);  
  10.     }  
  11.       
  12.     private OnClickListener listener=new OnClickListener() {  
  13.         @Override  
  14.         public void onClick(View v) {  
  15.             imageView.setVisibility(View.VISIBLE);  
  16.             //加载动画  
  17.             Animation animation=AnimationUtils.loadAnimation(MainActivity.this,R.anim.player_double_click_animation);  
  18.             imageView.startAnimation(animation);//开始动画  
  19.             animation.setAnimationListener(new AnimationListener(){  
  20.                 @Override  
  21.                 public void onAnimationStart(Animation animation) {}  
  22.                 @Override  
  23.                 public void onAnimationRepeat(Animation animation) {}  
  24.                 @Override  
  25.                 public void onAnimationEnd(Animation animation) {//动画结束  
  26.                     imageView.setVisibility(View.GONE);  
  27.                 }  
  28.             });  
  29.         }  
  30.     };  
  31. }  


效果图如下:




点击下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值