Ari*_*Roy 23 android image-rotation android-animation android-imageview
是)我有的
我有一个箭头图像(如左图).当用户点击它时,它应该用动画旋转180度,看起来应该是正确的.
我做了什么
private void rotate(float degree, final int toggleV) {
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(500);
toggle.startAnimation(rotateAnim);
rotateAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (toggleV == 1)
toggle.setImageResource(R.drawable.toggle_up);
else
toggle.setImageResource(R.drawable.toggle_down);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
Run Code Online (Sandbox Code Playgroud)
问题
我看到动画工作正常,但设置图像时有一点闪烁.可能是因为动画结束和设置图像时的时差.
如何删除此闪烁问题?你有更好的方法吗?
Zso*_*agy 54
首先,您最低SDK要求是什么?如果它至少是Android 3.0,您可以使用更新的动画框架,并使用以下内容为您的Image设置动画:
imageView.animate().rotation(180).start();
Run Code Online (Sandbox Code Playgroud)
关于闪烁:我不会在旋转后重置ImageView的源图像,我只需保留原始图像并确保旋转动画在动画后填充,使图像旋转.闪烁很可能是由于在更改源图像时View的重新布局/重绘造成的.
可能引起进一步的视觉伪像(闪烁?),因为原始旋转的图像和旋转的静态图像可能在几个像素中不同.
归档时间: |
|
查看次数: |
21296 次 |
最近记录: |