How to rotate a drawable by ObjectAnimator?

后端 未结 2 1519
面向向阳花
面向向阳花 2020-12-17 09:57

Alphaing a drawable work well like this:

if(mAlphaAnimation == null){
        mAlphaAnimation = ObjectAnimator.ofFloat(this, \"alpha\", 0.0f,1.0f).setDurati         


        
2条回答
  •  既然无缘
    2020-12-17 10:30

    Try with ObjectAnimator instead.

    ImageView imageview = (ImageView)findViewById(R.id.image);
    
    ObjectAnimator imageViewObjectAnimator = ObjectAnimator.ofFloat(imageview ,
                        "rotation", 0f, 360f);
                imageViewObjectAnimator.setDuration(1000); // miliseconds
                imageViewObjectAnimator.start();
    

    EDIT Since this question draw some attention let me to explain why to use ObjectAnimator instead of other Transition animators

    The thing about using ObjectAnimator is that it's moving both the visible and the clickable area of the item, if you use another animation method, for example Transition Animation or some other Animators, and let's say if you want to move the Button from the bottom left of the screen to the top left, it will only move the visible area but not the Button itself, the clickable area will still be on the previous position, in this case the clickable area will still be on the bottom left instead of the top left where you moved the button.

    If you do the same with ObjectAnimator, both the visible area, and the clickable area will move the the desired location.

提交回复
热议问题