Android模拟器复选框和无线电按钮错误 - UI上显示了各种不正确的状态

发布于 2025-02-10 19:53:54 字数 562 浏览 2 评论 0原文

最近,我发现了奇怪的模拟器行为,显示了无线电按钮和复选框。它不具有2个UI状态,或者更具体地说,它显示了4个不同甚至更多的状态。我想它们是冷冻的动画状态。在布局检查器和较新版本的API上,它看起来正常。请参阅下面的图片:

“模拟器上的复选框”

我在API版本中发现了它:23和24。在28和30上,它的行为正确。

因此,问题是:这真的是模拟器的问题,并且不会在真实设备上发生吗?也许这是某些设置的问题?

编辑:它不仅在模拟器上发生。

Recently I've spotted weird emulator behaviour with showing the radio buttons and checkboxes. Instead of having only 2 states of UI it has or to be more specific it shows 4 different or even more. I suppose they are frozen animation states. On the layout inspector and on the newer version of the API it looks normal. See the pictures below:

checkboxes on the emulator
checkboxes on the layout inspector

I spotted it at Api versions: 23 and 24. And on 28 and 30 it behaves correctly.

So the question is: is it really a problem of the emulator and it won't happen on real devices? Or maybe it is a matter of some settings?

Edit: It is happening not only on emulators.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦行僧 2025-02-17 19:53:54

我发现了这种不正确的复合按钮状态的原因。这是因为我使用插图在这样的按钮之前添加左填充物:

fun CompoundButton.addButtonDrawableInsets(insetDp: Int) {
    val originalDrawable = buttonDrawable ?: return
    buttonDrawable = InsetDrawable(originalDrawable, dp(insetDp))
}

我试图找到一种方法来添加不同的填充方法,但我最终将每个按钮包裹着其他Framelayout并在此处添加填充。提防Radiogroup,因为如果它没有直接的孩子作为RadioButton,那么它的功能就会中断,并且您必须自己实现重新选择以前的按钮。

I've found the reason for such incorrect states of compound buttons. It's is because I've used an Inset to add left padding before the button like that:

fun CompoundButton.addButtonDrawableInsets(insetDp: Int) {
    val originalDrawable = buttonDrawable ?: return
    buttonDrawable = InsetDrawable(originalDrawable, dp(insetDp))
}

I tried to find a way to add padding differently but I've ended up wrapping every button with additional FrameLayout and adding padding there. Watch out with RadioGroup because if it doesn't have a direct child as RadioButton then its functionality breaks and you have to implement reselecting previous buttons by yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文