How to code an animation for refresh icon

2019-07-28 18:00发布

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条回答
女痞
2楼-- · 2019-07-28 18:14

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.

查看更多
登录 后发表回答