Android 动画集合
2016-12-11 17:48
260 查看
tween动画是放置到res/anim/下面
frame动画是放置到res/drawable/下面
frame动画是放置到res/drawable/下面
Frame动画
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" > <item android:drawable="@drawable/girl_1" android:duration="200"/> <item android:drawable="@drawable/girl_2" android:duration="200"/> <item android:drawable="@drawable/girl_3" android:duration="200"/> <item android:drawable="@drawable/girl_4" android:duration="200"/> <item android:drawable="@drawable/girl_5" android:duration="200"/> <item android:drawable="@drawable/girl_6" android:duration="200"/> <item android:drawable="@drawable/girl_7" android:duration="800"/> <item android:drawable="@drawable/girl_8" android:duration="200"/> <item android:drawable="@drawable/girl_9" android:duration="200"/> <item android:drawable="@drawable/girl_10" android:duration="200"/> <item android:drawable="@drawable/girl_11" android:duration="200"/> </animation-list>
public class FrameActivity extends Activity { private ImageView iv ; //AnimationDrawable核心对象 private AnimationDrawable drawable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); iv = (ImageView) this.findViewById(R.id.iv); iv.setBackgroundResource(R.drawable.list); drawable = (AnimationDrawable) iv.getBackground(); } @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction()==MotionEvent.ACTION_DOWN){ //开始播放帧动画 drawable.start(); } return super.onTouchEvent(event); } }
Tween动画
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="alpha" android:text="透明度" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="rotate" android:text="旋转" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="scale" android:text="缩放" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="translate" android:text="平移" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="set" android:text="组合动画" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:gravity="center_vertical|center_horizontal" > <ImageView android:scaleType="fitXY" android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> </LinearLayout> </LinearLayout>
<?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" 动画效果重复的模式 参数有重新开始和倒着执行的模式 android:interpolator="@android:anim/decelerate_interpolator"减速加速器 > </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" 代表当前的中间位置 加上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:pivotx="0.0" android:pivoty="50.0" Y轴中间 android:fromXScale="0.0" 开始x轴比例 android:toXScale="2.0" 结束x轴比例 android:fromYScale="0.0" 开始x轴比例 android:toYScale="2.0" android:repeatMode="reverse" 重复相反的模式 android:repeatCount="1" > </scale>
<?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" 动画开始时间 1秒之后开始播放动画 > </translate>
<?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>
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); //AnimationUtils动画工具类,把一个资源文件转换成一个动画效果 Animation aa = AnimationUtils.loadAnimation(this, R.anim.alpha); iv.startAnimation(aa); } /** * 播放旋转变化的动画 * */ public void rotate(View view){ //第一个参数是从0角度开始,第二个参数到90角度结束 //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){ //第一二个参数是从x轴完全不可见到完全可见,第三四个参数是从y轴完全不可见到完全可见 // 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){ //第一个参数偏移开始x轴坐标,第二个参数偏移结束x轴坐标,第三个参数偏移开始y轴的坐标,第四个参数偏移结束y轴的坐标 // 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); } }
相关文章推荐
- Android的Activity跳转动画集合
- Android的一些动画集合以及LayoutAnimation的一些用法
- Android github上开源项目、酷炫的交互动画和视觉效果地址集合
- 记录一个Android动画集合
- android的一些动画集合以及layoutAnimation的一些用法
- Android 动画之集合动画AnimatorSet
- Android 动画 - AnimationSet 动画集合使用(附图)
- Android 动画特效集合
- Android动画集合
- Android动画学习笔记大集合
- Android 动画特效集合
- Android 动画特效集合
- android的一些动画集合以及layoutAnimation的一些用法
- Android动画学习笔记大集合
- 【Android】xml实现简单动画集合
- Android 补间动画(动画列表,平移,旋转,缩放,渐变,动画集合)
- Android开发笔记(九十六)集合动画与属性动画
- android github上开源项目、酷炫的交互动画和视觉效果集合
- Android动画效果集合开源APP
- android的一些动画集合以及layoutAnimation的一些用法