Android ImageView Animation

前端 未结 9 1057
忘掉有多难
忘掉有多难 2020-12-04 07:32

I\'ve created a layout with an image view and a web view. The web view is set to have a default visibility of gone. When the activity fires up it displays the image view fir

9条回答
  •  情书的邮戳
    2020-12-04 08:22

    How to rotate an image around its center:

    ImageView view = ... //Initialize ImageView via FindViewById or programatically
    
    RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    
    //Setup anim with desired properties
    anim.setInterpolator(new LinearInterpolator());
    anim.setRepeatCount(Animation.INFINITE); //Repeat animation indefinitely
    anim.setDuration(700); //Put desired duration per anim cycle here, in milliseconds
    
    //Start animation
    view.startAnimation(anim); 
    //Later on, use view.setAnimation(null) to stop it.
    

    This will cause the image to rotate around its center (0.5 or 50% of its width/height). I am posting this for future readers who get here from Google, as I have, and who wish to rotate the image around its center without defining said center in absolute pixels.

提交回复
热议问题