一丶代码见本文
二丶效果演示(略)
都是常见的口述即可理解
三丶课程讲解
这一节的图片讲解讲解的相当清楚了,五个anim.xml对应五个效果,这里就直接复制anim.xml和MainActivity.java
平移
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="3000" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="300" android:toYDelta="300"/> </set>缩放
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="0.0" android:fromYScale="0.0" android:toXScale="1.0" android:toYScale="1.0" android:fillAfter="false" android:duration="3000" android:pivotX="50%" android:pivotY="50%"/> </set>旋转
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:duration="3000" android:fromDegrees="0" android:toDegrees="360" android:pivotY="50%" android:pivotX="50%"/> </set>切换
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable="@mipmap/a" android:duration="300"/> <item android:drawable="@mipmap/b" android:duration="300"/> <item android:drawable="@mipmap/c" android:duration="300"/> </animation-list>透明度
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="3000"/> </set>MainActivity
public class MainActivity extends ActionBarActivity { ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.imageView2); } public void click2(View view){ AnimationDrawable ad = (AnimationDrawable) iv.getDrawable(); ad.start(); // ad.stop(); // } public void click(View view){ // Animation alphaAnimation = new AlphaAnimation(0.0f,1.0f); //加载动画资源文件 Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha_anim); Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale_anim); Animation translate = AnimationUtils.loadAnimation(this, R.anim.translate_anim); Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate_anim); ImageView iv = (ImageView) view; //启动动画 iv.startAnimation(rotate); } }
1111