用XML文件来设置旋转动画属性
1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android"> 3 4 <!--
5 pivotX:动画旋围绕点的X轴位置 pivotY:动画旋转围绕点的Y轴位置 50%是中心 6 fromDegress:动画开始的初始角度 7 toDegrees:动画结束的角度 8 --> 9 <rotate 10 android:fromDegrees="180" 11 android:toDegrees="360" 12 android:duration="2000" 13 android:repeatCount="2" 14 /> 15 </set>
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 tools:context="com.test2_23.test2_23.xml_RotateActivity"> 5 <ImageView 6 android:id="@+id/rotate_xml_img" 7 android:src="@drawable/img_bird" 8 android:layout_width="wrap_content" 9 android:layout_height="wrap_content" /> 10 </RelativeLayout>
1 public class xml_RotateActivity extends Activity { 2 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_xml__rotate); 7 ImageView img = (ImageView) findViewById(R.id.rotate_xml_img); 8 Animation animation = AnimationUtils.loadAnimation(this,R.anim.animtation_rotate); 9 img.clearAnimation(); 10 img.startAnimation(animation); 11 } 12 }
原文:http://www.cnblogs.com/androidLearn/p/5213953.html