我有一个带有动态添加 RadioButtons 的 RadioGroup。在我的 Activity 中,我在选择 RadioButton 后立即关闭 Activity 。但是,这会导致一个工件,其中两个 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);
最佳答案
为了让用户看到他们选择的 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()
}
关于android - 如何在 Android 上加快或关闭 RadioButton 的动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41619267/