补间动画效果

1.主函数

public class TweenActivity02 extends AppCompatActivity {
    private ImageView iv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tween02);
        iv = (ImageView) findViewById(R.id.icon);
    }
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_alpha:
//                透明度动画:1,实例化透明度动画的对象
//                第一个参数:表示起初的透明度      第二个参数:表示结尾的透明度
                AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.2f);
//                设置持续的持续的时间
                alphaAnimation.setDuration(3000);
//                设置保存的状态
                alphaAnimation.setFillAfter(true);
//                设置重复的次数
                alphaAnimation.setRepeatCount(1);
//                设置重复的模式
                alphaAnimation.setRepeatMode(Animation.REVERSE);
//                为控件启动动画
                iv.startAnimation(alphaAnimation);
                break;
            case R.id.btn_scale:
                /**fromX   :x轴起始位置
                 * toX     :x轴结束位置
                 * fromY  :y轴起始位置
                 * toY    :y轴结束位置
                 * pivotXType   : x轴缩放中心点类型
                 *          Animation.RELATIVE_TO_SELF
                 *          Animation.RELATIVE_TO_PARENT
                 * pivotXValue   : x轴缩放中心点值
                 * pivotYType .  :  y轴缩放中心点类型
                 * pivotYValue  :  y轴缩放中心点值
                 */
//                1.实例化对象
                ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 3f, 1f, 3f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                scaleAnimation.setDuration(3000);
                scaleAnimation.setFillAfter(true);
                iv.startAnimation(scaleAnimation);
                break;
            case R.id.btn_tranlate:

                TranslateAnimation translateAnimation = new TranslateAnimation(0, 200, 0, 200);
                translateAnimation.setDuration(2000);
                translateAnimation.setFillAfter(false);
                translateAnimation.setRepeatMode(Animation.REVERSE);
                translateAnimation.setRepeatCount(1);
                iv.startAnimation(translateAnimation);

                break;
            case R.id.btn_rotate:

                RotateAnimation rotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                rotateAnimation.setDuration(3000);
                rotateAnimation.setFillAfter(true);

                iv.startAnimation(rotateAnimation);
                break;
            case R.id.btn_set:

//                1.实例化集合动画对象
                /**
                 * 参数: 分享插值器
                 * if  true  :使用set默认的插值器
                 * if false  :使用动画自己的插值器
                 * */
                AnimationSet set = new AnimationSet(true);

                AlphaAnimation alphaAnim = new AlphaAnimation(1.0f, 0.1f);
                RotateAnimation rotateAnim = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

//                2将动画放入到动画集当中
                set.addAnimation(alphaAnim);
                set.addAnimation(rotateAnim);

                set.setDuration(5000);
                set.setFillAfter(true);

                iv.startAnimation(set);
                break;
        }
    }
}





2.主布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.animee.day02.TweenActivity02">
    <Button
        android:id="@+id/btn_alpha"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="透明度动画"
        android:onClick="onClick"/>

    <Button
        android:id="@+id/btn_scale"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="缩放渐变动画"
        android:onClick="onClick"/>
    <Button
        android:id="@+id/btn_tranlate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="移动动画"
        android:onClick="onClick"/>
    <Button
        android:id="@+id/btn_rotate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="旋转动画"
        android:onClick="onClick"/>
    <Button
        android:id="@+id/btn_set"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="集合动画"
        android:onClick="onClick"/>

    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:id="@+id/icon"
        android:src="@mipmap/h2"
        android:layout_gravity="center"/>
</LinearLayout>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值