旋转后刷新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();
}