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

标签 android android-radiogroup android-radiobutton

我有一个带有动态添加 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/

相关文章:

android - 使用 FragmentStatePagerAdapter 并启动新 Activity 时出现 TransactionTooLargeException

内容提供者中的Android自定义方法获取表中的记录数?

android - 如何找出选定的单选选项,当 android :radiobutton ="@null" in android?

Android RadioButton *带有*图标并居中对齐

android - 对齐 RadioButton 下方的文本

android - 具有下拉菜单 View 的操作项

javascript - WL.App.overrideBackButton 不起作用

android - 具有相应标签的 radio 组的 TableLayout 在 android 中对齐

android - 如何在垂直方向的android单选按钮之间提供间距

android - 居中 RadioGroup 中 RadioButton 的图标