Eliminate extra right padding android radio button on Samsung Galaxy S3 on Jellybean API Level 16

ぐ巨炮叔叔 提交于 2019-12-12 10:17:05

问题


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?

May be related to this issue: Android CheckBox extra padding on TouchWiz

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>

Thanks.


回答1:


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 -->


来源:https://stackoverflow.com/questions/23251003/eliminate-extra-right-padding-android-radio-button-on-samsung-galaxy-s3-on-jelly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!