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

VIN*_*VIN 5 android android-radiogroup android-radiobutton

我有一个带有动态添加的 RadioButtons 的 RadioGroup。在我的活动中,我在选择 RadioButton 后立即关闭活动。然而,这会导致一个工件,其中两个 RadioButton 看起来像是在 Activity 完成之前被选中。当 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);
Run Code Online (Sandbox Code Playgroud)

cai*_*des 1

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

radioGroup.setOnCheckedChangeListener { radioGroup, checkedId ->
    Handler(Looper.getMainLooper()).postDelayed(
        {
            finish()
        },
        500
    )
}
Run Code Online (Sandbox Code Playgroud)

如果您想删除动画,可以在这里看到答案: https: //stackoverflow.com/a/51411238/1212331

例如

radioGroup.setOnCheckedChangeListener { radioGroup, checkedId ->
    radioGroup.jumpDrawablesToCurrentState()
}
Run Code Online (Sandbox Code Playgroud)