tween动画

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="2000"
    android:repeatCount="0"
    android:repeatMode="restart"
    >
</alpha>
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="90"
    android:pivotX="50%p"
    android:pivotY="50%p"
    android:duration="2000"
    >
</rotate>
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="2000"
    android:fromXScale="0.0"
    android:toXScale="2.0"
    android:fromYScale="0.0"
    android:toYScale="2.0"
    android:repeatMode="reverse"
    android:repeatCount="1"
    >

</scale>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration="2000"
        android:fromAlpha="0.0"
        android:repeatCount="0"
        android:repeatMode="restart"
        android:toAlpha="1.0" />

    <rotate
        android:duration="2000"
        android:fromDegrees="0"
        android:pivotX="50%p"
        android:pivotY="50%p"
        android:toDegrees="90" />

    <scale
        android:duration="2000"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:toXScale="2.0"
        android:toYScale="2.0" />

</set>
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="2000"
    android:fromXDelta="0"
    android:toXDelta="100"
    android:fromYDelta="0"
    android:toYDelta="100"
    android:startOffset="1000"
    >

</translate>
package cn.itcast.anim;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class DemoActivity extends Activity {
	private ImageView iv;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        iv = (ImageView) this.findViewById(R.id.iv);
    }
    
    
    /**
     * 点击事件播放透明度变化的动画 
     * 
     */
    public void alpha(View view){
	//完全透明到完全不透明
//    	AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f);
//    	aa.setDuration(2000);
//也可以用布局里面的布局
    	Animation aa = AnimationUtils.loadAnimation(this, R.anim.alpha);
		//1得到动画  2imageview开始动画
    	iv.startAnimation(aa);
    	
    }
    /**
     * 播放选择变化的动画 
     * 
     */
    public void rotate(View view){
    	//RotateAnimation ra = new RotateAnimation(0, 90);
    	//RotateAnimation ra = new RotateAnimation(0, 90, (iv.getRight()+iv.getLeft())/2, (iv.getTop()+iv.getBottom())/2);
    	// 怎么去定义旋转的中间位置?
//    	RotateAnimation ra = new RotateAnimation(0, 90, 0.5f, 0.5f);
//    	ra.setDuration(2000);
    	Animation ra = AnimationUtils.loadAnimation(this, R.anim.rotate);
    	iv.startAnimation(ra);
    }
    
    
    public void scale(View view){
//    	ScaleAnimation sa = new ScaleAnimation(0.0f, 2.0f, 0.0f, 2.0f);
//    	sa.setDuration(2000);
    	Animation sa  = AnimationUtils.loadAnimation(this, R.anim.scale);
    	
    	
    	iv.startAnimation(sa);
    }
    
    
    public  void translate(View view){
//    	TranslateAnimation ta = new TranslateAnimation(0, 200, 0, 200);
//    	ta.setDuration(2000);
    	Animation ta  = AnimationUtils.loadAnimation(this, R.anim.translate);
    	iv.startAnimation(ta);
    }
    
    /**
     * 动画的组合
     */
    public void set(View view){
//    	AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f);
//    	aa.setDuration(2000);
//    	RotateAnimation ra = new RotateAnimation(0, 90);
//    	ra.setDuration(2000);
//    	TranslateAnimation ta = new TranslateAnimation(0, 200, 0, 200);
//    	ta.setDuration(2000);
//得到动画集
//    	AnimationSet set = new AnimationSet(false);
//    	set.addAnimation(ta);
//    	set.addAnimation(ra);
//    	set.addAnimation(aa);
//将动画都放入后,开始动画集.
//    	iv.startAnimation(set);
    	Animation aa = AnimationUtils.loadAnimation(this, R.anim.set);
    	iv.startAnimation(aa);
    }
    
}






你可能感兴趣的:(tween动画)