Android tween动画(补间动画)
2017-05-03 18:55
387 查看
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:onClick="rotate" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="旋转" /> <Button android:onClick="scale" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="缩放" /> <Button android:onClick="trans" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="位移" /> <Button android:onClick="alpha" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="透明度" /> <Button android:onClick="set" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="组合动画" /> </LinearLayout> <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:src="@drawable/ic_launcher" /> </RelativeLayout>
public class MainActivity extends Activity { private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv); } //透明度动画 public void alpha(View view){ AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f); aa.setDuration(2000); aa.setRepeatCount(1); aa.setRepeatMode(Animation.REVERSE); aa.setFillAfter(true); iv.startAnimation(aa); } //位移动画 public void trans(View view){ TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.5f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f); ta.setDuration(2000); ta.setRepeatCount(1); ta.setRepeatMode(Animation.REVERSE); iv.startAnimation(ta); } //缩放动画 public void scale(View view){ ScaleAnimation sa = new ScaleAnimation(0.1f, 2.0f, 0.1f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); sa.setDuration(2000); sa.setRepeatCount(1); sa.setRepeatMode(Animation.REVERSE); iv.startAnimation(sa); } //旋转动画 public void rotate(View view){ RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); ra.setDuration(2000); ra.setRepeatCount(1); ra.setRepeatMode(Animation.REVERSE); iv.startAnimation(ra); } //动画组合 public void set(View view){ AnimationSet set = new AnimationSet(false); TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.5f, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, -0.5f, Animation.RELATIVE_TO_PARENT, 0.5f); ta.setDuration(2000); ta.setRepeatCount(1); ta.setRepeatMode(Animation.REVERSE); ScaleAnimation sa = new ScaleAnimation(0.1f, 2.0f, 0.1f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); sa.setDuration(2000); sa.setRepeatCount(1); sa.setRepeatMode(Animation.REVERSE); RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); ra.setDuration(2000); ra.setRepeatCount(1); ra.setRepeatMode(Animation.REVERSE); set.addAnimation(ra); //set.addAnimation(ta); set.addAnimation(sa); iv.startAnimation(set); } }
参考:
Android动画
相关文章推荐
- Android--Tween补间动画
- android—补间动画(Tween Animation)旋转的血轮眼
- Android笔记(六十四) android中的动画——补间动画(tweened animation)
- android 补间(Tween)动画
- Android动画主要包含补间动画(Tween)View Animation、帧动画(Frame)Drawable Animation、以及属性动画Property Animation
- Android中的补间动画(tween)的简单使用
- Android 补间动画(Tween)之二,自定义补间动画
- Android动画之补间动画(Tween Animation)实例详解
- android动画之:补间动画(Tween动画)
- Android补间动画(View Animation,Tweened Animation)
- Android动画-补间(Tween)动画
- android 补间动画 tween animation xml基本属性
- android基础笔记——补间动画(Tween)代码实现
- android补间动画(tween animation)xml基本属性
- Android开发(26)--补间动画(Tween)的实现
- Android两大动画之Tween(补间动画)详解
- Android——动画之补间动画(Tween动画)
- Android的图形与图像处理之四 补间动画(Tween)
- Android动画1-补间动画(TweenAnimation)
- Android 连续的补间动画(Animation/Tween)