Android之补间动画

Android三种动画中的第二种——补间动画(Tween),和前面学的帧动画不同,帧动画 是通过连续播放图片来模拟动画效果,而补间动画开发者只需指定动画开始,以及动画结束"关键帧", 而动画变化的"中间帧"则由系统计算并补齐。

1.第一步:xmL中定义动画属性(移动、透明、旋转、放大放小)可以统一在se集合当中存放:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate
        android:fromDegrees="0"
        android:toDegrees="360"
        android:duration="2000"
        />
    <translate
        android:duration="2000"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:toXDelta="0"
        android:toYDelta="30"
        android:pivotY="50%"
        android:pivotX="50%"
        />
    <alpha
        android:fromAlpha="0"
        android:toAlpha="1"
        android:duration="2000"
        />
    <scale
        android:duration="2000"
        android:fromXScale="0dp"
        android:fromYScale="0dp"
        android:toXScale="100dp"
        android:toYScale="100dp"
        />
</set>

2.布局文件:

    <Button
        android:id="@+id/give_frame"
        android:text="补间动画效果一"
        android:textSize="25dp"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <ImageView
        android:id="@+id/image1"
        android:layout_marginTop="100dp"
        android:background="@drawable/a"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/give_frame2"
        android:text="补间动画效果二"
        android:textSize="25dp"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <ImageView
        android:id="@+id/image2"
        android:layout_marginTop="100dp"
        android:background="@drawable/a"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

2.Java代码实现:


    @Event(type = View.OnClickListener.class,value = R.id.add_frame)
    private void add_frameonClick(View view){
        //动画工具集:
        Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.starr);
        //动画结束的时候保存最后位置的状态:
        animation.setFillAfter(true);
        ///动画结束的时候保存最开始位置的状态:
        animation.setFillBefore(true);
        //动画监听器:
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                long startTime = animation.getStartTime();
                Log.i("asdasd","开始动画时间:"+startTime);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                long startOffset = animation.getStartOffset();
                Log.i("asdasd","动画准备持续时间:"+startOffset);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                int repeatCount = animation.getRepeatCount();
                Log.i("asdasd","动画重复的次数:"+repeatCount);
            }
        });
        add_frame.startAnimation(animation);
    }

3.附加一个跳转Activity动画效果实现:

 //跳转动画:
    @Event(type = View.OnClickListener.class,value = R.id.intent)
    private void intentonClick(View view){
        Intent intent=new Intent(MainActivity.this,Main2Activity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.starr2,R.anim.out);
    }

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值