旋转后刷新android ImageButton
我的片段中有一个旋转后刷新android ImageButton,android,imagebutton,Android,Imagebutton,我的片段中有一个ImageButton,它的背景设置为一个android可绘制图标。在某些情况下,该按钮需要旋转(此操作有效)。我的问题是,当我在另一个活动中返回片段时,我希望按钮“重置”到其原始位置 以下是按钮的设置方式: @Override public void onViewCreated(final View view, Bundle savedInstanceState) { button = (ImageButton)view.findViewById(R.id.doButt
ImageButton
,它的背景设置为一个android可绘制图标。在某些情况下,该按钮需要旋转(此操作有效)。我的问题是,当我在另一个活动中返回片段时,我希望按钮“重置”到其原始位置
以下是按钮的设置方式:
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
button = (ImageButton)view.findViewById(R.id.doButtonThing);
button.setOnClickListener(this);
if (condition) {
button.animate().rotation(90f).setInterpolator(new AccelerateDecelerateInterpolator());
}
}
我试过使用:
button.clearAnimation();
button.invalidate();
button.postInvalidate();
在onResume()
方法中,但它们都不起作用。如何重置/重新加载原始按钮?clearAnimation()的代码
这给我的印象是它清除了当前正在运行的动画(尽管我不确定)。而不是按钮。clearAnimation()代码>,可以使用按钮.animate().rotation(0.0f)代码>反向旋转按钮
另外,我建议您以后调用该函数,而不是onResume()
,可能是onStop()
。在生命周期中,onResume()
位于onViewCreated(最终视图,Bundle savedInstanceState)
之后,在onResume()中调用它将使动画无效。按钮.动画().旋转(0.0f)
做了这个把戏,我不知怎的认为它不会旋转已经旋转的按钮,但我猜它会记住原始状态并重置它。谢谢你的帮助,我会把它移到onStop()
。
/**
* Cancels any animations for this view.
*/
public void clearAnimation() {
if (mCurrentAnimation != null) {
mCurrentAnimation.detach();
}
mCurrentAnimation = null;
invalidateParentIfNeeded();
}