xml写动画

前端之家收集整理的这篇文章主要介绍了xml写动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
public class Main21 extends Activity implements OnClickListener{
	
	private Button main20_rotate;
	private Button main20_scale;
	private Button main20_alpha;
	private Button main20_translate;
	private ImageView main20_image;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main20);  
		main20_rotate=(Button)this.findViewById(R.id.main20_rotate);  //旋转  
        main20_rotate.setOnClickListener(this);  
        main20_scale=(Button)this.findViewById(R.id.main20_scale);  //缩放  
        main20_scale.setOnClickListener(this);  
        main20_alpha=(Button)this.findViewById(R.id.main20_alpha);  //淡入淡出  
        main20_alpha.setOnClickListener(this);  
        main20_translate=(Button)this.findViewById(R.id.main20_translate);  //移动  
        main20_translate.setOnClickListener(this);  
          
        main20_image=(ImageView)this.findViewById(R.id.main20_image);  
		
	}

	@Override  
    public void onClick(View v) {  
        
        switch (v.getId()) {  
        case R.id.main20_rotate:     //旋转  
              
            Animation rotate=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.main21_rotate);     	
            main20_image.startAnimation(rotate);  
            break;  
              
        case R.id.main20_scale:     //缩放      
            
        	 Animation scale=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.main21_scale);
             main20_image.startAnimation(scale);  
            break;  
              
        case R.id.main20_alpha:   //淡入淡出  
        	 Animation alpha=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.main21_alpha);
             main20_image.startAnimation(alpha);  
            break;  
        case R.id.main20_translate:   // 移动  
        	Animation translate=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.main21_translate);
            main20_image.startAnimation(translate);    
            break;  
        default:  
            break;  
        }  
          
    }  

}  


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

</set>

猜你在找的XML相关文章