给控件设置各种小动画效果

1  rootView.findViewById(R.id.btnAnimMe).setOnClickListener(new View.OnClickListener() {
2                 @Override
3                 public void onClick(View arg0) {
4                 //    AlphaAnimation aa = new AlphaAnimation(0, 1);
5                 //    aa.setDuration(1000);
6                 //    arg0.startAnimation(aa);
7                     arg0.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.aa));
8                 }
9             });
xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="0"
    android:toAlpha="1"
    android:duration="1000" >
alpha>
xml version="1.0" encoding="utf-8"?>

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:duration="1000"
    android:pivotX="50%"
    android:pivotY="50%" >
rotate>
xml version="1.0" encoding="utf-8"?>

<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXScale="0"
    android:toXScale="1"
    android:fromYScale="0"
    android:toYScale="1"
    android:duration="1000"
    android:pivotX="50%"
    android:pivotY="50%" >
scale>
 1 import android.view.animation.Animation;
 2 import android.view.animation.Transformation;
 4 /**
 5  * 按钮左右晃动
 6  * 
 7  * ca = new CustomAnim();
 8  * ca.setDuration(1000);
 9  * findViewById(R.id.btnAnimMe).setOnClickListener(new View.OnClickListener() {
10  *     @Override
11  *     public void onClick(View arg0) {
12  *        arg0.startAnimation(ca);
13  *     }
14  * });
15  */
16 public class CustomAnim extends Animation {
17 
18     @Override
19     public void initialize(int width, int height, int parentWidth,
20             int parentHeight) {
21         super.initialize(width, height, parentWidth, parentHeight);
22     }
23     
25     @Override
26     protected void applyTransformation(float interpolatedTime, Transformation t) {
27 //        System.out.println(interpolatedTime);
28 //        t.setAlpha(interpolatedTime);
29 //        t.getMatrix().setTranslate(200*interpolatedTime, 200*interpolatedTime);
30         t.getMatrix().setTranslate((float) (Math.sin(interpolatedTime*20)*50), 0);
31         
32         super.applyTransformation(interpolatedTime, t);
33     }   
35 }

 

转载于:https://www.cnblogs.com/androidsj/p/4476423.html

你可能感兴趣的:(给控件设置各种小动画效果)