如何在Android上加快或关闭RadioButton的动画?

时间:2017-01-12 17:19:28

标签: android android-radiogroup android-radiobutton

我有一个动态添加了RadioButtons的RadioGroup。在我的Activity中,我在选择RadioButton后立即关闭活动。但是,这会导致一个神器,其中两个RadioButton看起来像在Activity完成之前被选中。活动结束时,先前的选择和当前选择仍然是动画。

有没有办法加速动画或完全禁用它,以便我看不到这个视觉神器?

radioButton.setChecked(true);   // previous selected button is still deselecting and current button is now selecting. both are in the middle of animating but activity closes before they can finish animating  
finishWithResult(selected == null ? Activity.RESULT_CANCELED : Activity.RESULT_OK, selectedItem);

1 个答案:

答案 0 :(得分:0)

为了让用户看到他们选择的 RadioButton 的选择,您可以延迟关闭 Activity 而不是关闭 RadioButton 选择动画。

radioGroup.setOnCheckedChangeListener { radioGroup, checkedId ->
    Handler(Looper.getMainLooper()).postDelayed(
        {
            finish()
        },
        500
    )
}

如果您无论如何都想移除动画,您可以在此处查看答案:https://stackoverflow.com/a/51411238/1212331

例如

radioGroup.setOnCheckedChangeListener { radioGroup, checkedId ->
    radioGroup.jumpDrawablesToCurrentState()
}