问题
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