旋转(rotate)
01 alpha动画
public void doAlpha(View v){ Animation animation; animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.alpha); (方法一: alpha.xml: <alpha android:fromAlpha="0" android:toAlpha="1" android:duration ="5000" xmlns:android = "http://schemas.android.com/apk/res/android"> ) //方法二: animation = new AlphaAnimation(0f,1f); animation.setDuration(5000);(设置时间,以毫秒为单位) imageview.startAnimation(animation); }
02 平移(translate)
<translate android:duration="2000" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="100%" android:toYDelta="100%" android:fillAfter="true"(保持动画结束状态) android:repeatCount="1"(重复的次数,不包括第一次) android:repeaMode="reverse"(返回) android:repeaMode="restart"(重新开始) android:fillBefore ></translate> public void doTranslate(View v){ Animation animation; animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.translate); imageview.startAnimation(animation); }
<scale android:fromXScale="0" android:fromYScale="0" android:toScale="100%" android:toScale="100%" <--设置中心点位置--> android:pivotX="0" android:pivotY="0" ></scale> public void doScale(View v){ Animation animation; animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.scale); imageview.startAnimation(animation); }
<rotate android:fromDegrees="0" android:toDegrees="360"(可以设置旋转圈数) android:duration="2000" android:interpolator(用来设置加速方式) android:repeatCount="2"(也可以设置旋转圈数) android:pivotX="50%" android:pivotY="50%"></rotate> public void doScale(View v){ Animation animation; animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.rotate); imageview.startAnimation(animation); }
<set <alpha android:duration="3000" android:fromAlpha="0" android:toAlpha="1"></alpha> <scale android:fromXScale="0" android:fromYScale="0" android:toXScale="100%" android:toYScale="100%" android:pivotX="50%" android:pivotY="50%" android:duration="3000"> </scale> <rotate android:duration="3000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:startOffset=""(设置开始时间,可以设置动画集相互播放的时间) android:toDegrees="720"/> </rotate> ></set> public void AnimationSet(View v){ Animation animation; animation = new AlphaAnimationUtils.loadAnimation(this,R.anim.set); imageview.startAnimation(animation); }
使用动画实现的图库:
主要代码:left_out_right.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="-100%" android:toXDelta="0" android:duration="1500" /> <alpha android:fromAlpha="0.75" android:toAlpha="1" android:duration="1500" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="100%" android:duration="1500" /> <alpha android:fromAlpha="0.5" android:toAlpha="1" android:duration="1500" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="-100%" android:duration="1500" /> <alpha android:fromAlpha="0.5" android:toAlpha="1" android:duration="1500" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="100%" android:duration="1500" /> <alpha android:fromAlpha="0.5" android:toAlpha="1" android:duration="1500" /> </set>
imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_to_left)); imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out_left));
imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_to_right)); imageswitcher.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out_right));