在 Jellybean API 级别 16 上消除三星 Galaxy S3 上额外的右填充 android 单选按钮单选、按钮、级别、Jellybean

2023-09-07 09:26:34 作者:她总是有理由-

在 Jellybean API 级别 16 的三星 Galaxy S3 上运行时,我看到单选按钮上有额外的右填充.(见屏幕截图).知道如何消除这种额外的右填充吗?

I am seeing extra right padding on radio buttons when ran on Samsung Galaxy S3 on Jellybean API Level 16. (see screenshot). Any idea how to eliminate this extra right padding?

可能与此问题有关:Android CheckBox extra padding on TouchWiz

布局 XML 如下所示:

Layout XML looks like this:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#ff0000">
    <RadioButton
        android:id="@+id/stw_no_thanks_radio"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="0dp"
        android:layout_margin="0dp"
        android:drawablePadding="0dp" />
</FrameLayout>

谢谢.

推荐答案

这似乎是 API 16 及更低版本的问题.API 17 不包括这个额外的空间.

This seems to be an issue with API 16 and lower. API 17 doesn't include this extra space.

此外,该问题似乎不是三星特有的(我能够在模拟器中重现该问题).

Also the issue doesn't seem specific to Samsung (I was able to reproduce the issue in the emulator).

这是我的解决方法,不确定它是否是最好的,但它解决了我的问题:

Here is my workaround, not sure if it is the best, but it solved my problem:

layout.xml

<RadioButton
    android:id="@+id/radio_button"
    android:layout_width="@dimen/radiobutton_width"
    android:layout_height="@dimen/radiobutton_height"
    android:padding="0dp"
    android:layout_margin="0dp" />

values/dimens.xml

<dimen name="radiobutton_width">38dp</dimen>
<dimen name="radiobutton_height">48dp</dimen>

values-v14/dimens.xml

<dimen name="radiobutton_width">32dp</dimen>
<dimen name="radiobutton_height">42dp</dimen>

values-v17/dimens.xml

<dimen name="radiobutton_width">-2dp</dimen> <!-- WRAP_CONTENT -->
<dimen name="radiobutton_height">-2dp</dimen> <!-- WRAP_CONTENT -->