码迷,mamicode.com
首页 > 其他好文 > 详细

属性动画

时间:2019-01-11 22:10:50      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:etc   end   new   div   ext   改变   listen   short   des   

public class MainActivity extends AppCompatActivity {

    private ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = findViewById(R.id.iv);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "你点不到我", Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void click1(View view) {
        ObjectAnimator oa = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            oa = ObjectAnimator.ofFloat(iv, "rotation", 0, 90, 180, 270, 360);
        }
        oa.setDuration(2000);
        oa.start();
    }

    public void click2(View view) {
        ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "alpha", 0.0f, 1.0f);
        oa.setDuration(2000);
        oa.start();
    }

    public void click3(View view) {
        ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "translationX", 0.0f, 10.0f, 20.0f, 100.0f);
        oa.setDuration(2000);
        oa.start();
    }

    public void click4(View view) {
        ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "scaleX", 1.0f, 2.0f);
        oa.setDuration(2000);
        oa.start();
    }

    public void click5(View view) {
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator oa1 = ObjectAnimator.ofFloat(iv, "rotation", 0, 90, 180, 270, 360);
        ObjectAnimator oa2 = ObjectAnimator.ofFloat(iv, "alpha", 0.0f, 1.0f);
        ObjectAnimator oa3 = ObjectAnimator.ofFloat(iv, "translationX", 0.0f, 10.0f, 20.0f, 100.0f);
        ObjectAnimator oa4 = ObjectAnimator.ofFloat(iv, "scaleX", 1.0f, 2.0f);
        animatorSet.playSequentially(oa1, oa2, oa3, oa4);
        animatorSet.setDuration(2000);
        animatorSet.setTarget(iv);
        animatorSet.start();
    }
}

 

  • 属性动画 会改变控件真实的坐标.

属性动画

标签:etc   end   new   div   ext   改变   listen   short   des   

原文地址:https://www.cnblogs.com/nangongyibin/p/10257432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!