Android单选按钮:移除左边填充

8

在这里输入图片描述

你好,我遇到了如上所示的问题。我面临的问题是,在所列出的单选按钮左侧似乎存在一个不可见的填充。我的问题是,这是由于单选按钮中的drawable问题还是可以调整属性来使其与我的文本和输入字段对齐。如果我需要使用替代drawable,是否有一个可以从SDK获取而没有边距/填充的drawable?

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
... stuff
    <RadioGroup
                android:layout_margin="0dp"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <RadioButton
                    android:id="@+id/radio_free_busy"
                    android:checked="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:drawablePadding="0dp"
                    android:text="@string/label_invitation_free_busy"
                    />
                <RadioButton
                    android:id="@+id/radio_free_busy_plus"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/label_invitation_free_busy_plus"
                    />
                <RadioButton
                    android:id="@+id/radio_none"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/label_invitation_none"
                    />
            </RadioGroup>
</LinearLayout>

似乎是由于可绘制对象引起的...如果有其他替代方案会很有帮助。

请问您能否展示一下您的代码? - Farouk Touzi
发布布局代码 - adrian
你确定你没有在RadioGroup的父视图中设置任何margin/padding吗? - joao2fast4u
没有父级,我刚刚发布的是默认设置。 - adrian
1
我其实刚刚意识到为什么http://android-holo-colors.com/是一个好的自动颜色生成器,它看起来像是按下时添加了一个效果,因此需要不可见的空间,唯一的方法就是向右移动左移等... - adrian
你解决了吗? - user924
2个回答

5
你说得对。我尝试了一下,并添加了一个负的左边距。
这是结果: enter image description here 我所做的是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="-3dp"
    android:orientation="vertical" >

    <RadioButton
        android:id="@+id/radio_free_busy"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:checked="true"
        android:drawablePadding="0dp"
        android:text="Free busy" />

    <RadioButton
        android:id="@+id/radio_free_busy_plus"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Invitation free busy plus" />

    <RadioButton
        android:id="@+id/radio_none"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Invitation none" />
</RadioGroup>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:text="Whate name should people in this group see ?" />


1

在单选按钮的XML中添加这个

android:minWidth="0dp"
android:minHeight="0dp"

所有额外的填充都将被移除。然后您可以调整边距。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接