属性动画



public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageButton imageButton;
    private Button dan;
    private Button zhuan;
    private Button yi;
    private Button zuhe;
    private Button suo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Animator animator = AnimatorInflater.loadAnimator(this, R.animator.objectanimator);
        animator.setTarget(imageButton);
        animator.start();

        initView();

    }

    private void initView() {
        imageButton = (ImageButton) findViewById(R.id.imageButton);
        dan = (Button) findViewById(R.id.button);
        zhuan = (Button) findViewById(R.id.button2);
        yi = (Button) findViewById(R.id.button3);
        zuhe = (Button) findViewById(R.id.button4);
        suo = (Button) findViewById(R.id.button5);

        dan.setOnClickListener(this);
        zhuan.setOnClickListener(this);
        yi.setOnClickListener(this);
        zuhe.setOnClickListener(this);
        suo.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button:
                ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageButton, "alpha", 1f, 0f, 1f);
                animator1.setDuration(5000);
                animator1.start();
                break;
            case R.id.button2:
                ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageButton, "rotationX", 0f, 360.0f);
                animator2.setDuration(5000);
                animator2.start();
                break;
            case R.id.button3:
                ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageButton, "translationY", 0f, 500f);
                animator3.setDuration(5000);
                animator3.start();
                break;
            case R.id.button4:
                AnimatorSet set = new AnimatorSet();
                ObjectAnimator animator22 = ObjectAnimator.ofFloat(imageButton, "rotationX", 0f, 360.0f);
                ObjectAnimator animator33 = ObjectAnimator.ofFloat(imageButton, "translationX", -500f, 0,500f,0f);
                set.playTogether(animator22,animator33);
                set.setDuration(5000);
                set.start();
                break;
            case R.id.button5:
                ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageButton, "scaleX", 1f, 0f,1f);
                scaleX.setDuration(5000);
                scaleX.start();
                break;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android属性动画是一种用于在Android应用程序中创建动画效果的框架。它允许您对任意对象的属性进行动画处理,而不仅仅是视图对象。使用属性动画,您可以平滑地改变对象的属性,如位置、大小、颜色等,从而创建流畅的动画效果。 属性动画的基本概念是通过改变对象的属性值来实现动画效果,而不是通过改变视图的位置或绘制来实现。这使得属性动画比传统的补间动画更加灵活和强大。 要使用属性动画,您需要创建一个Animator对象,并指定要动画化的目标对象和属性。然后,您可以定义动画的持续时间、插值器和监听器等属性。最后,启动动画并观察目标对象的属性值的平滑变化。 以下是一个简单的示例,演示如何使用属性动画来平滑地改变视图对象的透明度: ```java // 创建一个属性动画对象,指定要改变的属性为视图对象的透明度 ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha",***.setDuration(1000); // 设置插值器,控制动画的变化速率 animator.setInterpolator(new AccelerateDecelerateInterpolator()); // 启动动画 animator.start(); ``` 在上面的示例中,我们创建了一个ObjectAnimator对象,指定要改变的属性为视图对象的透明度。然后,我们设置了动*** 除了ObjectAnimator,Android还提供了一些其他类型的属性动画,如ValueAnimator和AnimatorSet。这些类可用于更复杂的动画效果,如同时播放多个动画或在动画中修改多个属性。 希望这个简介能帮助您理解Android属性动画的基本概念和用法。如果您有更多问题,请随时提问!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值