How to code an animation for refresh icon

人走茶凉 提交于 2019-12-11 08:59:41

问题


Issue at hand:

I am currently trying to code an animation function for the refresh icon and so far, through research I have only managed to source this code snippet out:

 LayoutInflater inflater= (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ImageView iv= (ImageView) inflater.inflate(R.layout.spin_refresh, null);
    Animation rotation= AnimationUtils.loadAnimation(DownloadService.this,R.anim.accelerate_decelerate_interpolator);
    rotation.setRepeatCount(Animation.INFINITE);
    iv.startAnimation(rotation);
    refreshItem.setActionView(iv);
    //TODO trigger loading

I couldn't actually fully comprehend the codings, are there any simpler way of animation coding or what's the general meaning of the code itself. I have already created a separate animation.xml within the animation folder in res folder.


回答1:


I guess you need to rotate the image to self like second animation in this post

You can use this:

image.clearAnimation();
RotateAnimation anim = new RotateAnimation(30, 360, image.getWidth()/2, image.getHeight()/2);
anim.setFillAfter(true);
anim.setRepeatCount(0);
anim.setDuration(10000);
image.startAnimation(anim); 

Hope this helps.



来源:https://stackoverflow.com/questions/25718765/how-to-code-an-animation-for-refresh-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!