属性动画 + handle 延时跳转

本文详细介绍了一个使用属性动画的示例,包括平移、旋转、透明度变化和缩放等效果,通过XML布局和Java代码结合实现,展示了如何在Android应用程序中创建复杂的动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先,属性动画是不用依赖的

定义xml文件中的图片

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:id="@+id/linearlayout"
    android:gravity="center"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher_round"/>

在activity中设置  代码如下:

public class MainActivity extends AppCompatActivity {

    private ImageView image;
    private LinearLayout linearlayout;
    private int width;
    private int height;
    private int time;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (time==0){
                startActivity(new Intent(MainActivity.this,FragMentActivity.class));
                finish();
            }

            time--;
            handler.sendEmptyMessageDelayed(0,1000);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        image = findViewById(R.id.image);
        linearlayout = findViewById(R.id.linearlayout);
        time=4;
        handler.sendEmptyMessageDelayed(0,1000);
        //平移
        ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(image, "translationY",image.getTranslationY(), 400);
        //旋转
        ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(image, "rotationY", 0, 360);
        //透明
        ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(image,"alpha",0,1,0,1);
        //缩放
        ObjectAnimator objectAnimator4 = ObjectAnimator.ofFloat(image, "scaleX", 0, 1);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(4000);
        animatorSet.play(objectAnimator1).with(objectAnimator2).with(objectAnimator3).with(objectAnimator4);
        animatorSet.start();

    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值