Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

layout - Text leftside of a RadioButton with a margin on Android

I want to have the "label", - the text you set in your RadioButton to show left of the button and have some padding in between.

Adding an additional TextView into the layout doesn't work because my RadioGroup does not work (i can choose multiple buttons) if i add anything other then a RadioButton into the RadioGroup.

So, how can i change the RadioButton to be <text><buttondrawable> instead of <buttondrawable><text>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can achieve this by setting android:button="@null" and adding the drawable of the RadioButton as android:drawableRight. You can change the Padding between the text and the drawable with android:drawablePadding .

    <RadioGroup
        android:id="@+id/radios"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:inputType="text"
        android:orientation="vertical" >

        <RadioButton
            android:id="@+id/first"
            android:button="@null"
            android:drawableRight="@android:drawable/btn_radio"
            android:drawablePadding="20dp"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="@string/first"
            android:textSize="20dip" />

        <RadioButton
            android:id="@+id/second"
            android:button="@null"
            android:drawableRight="@android:drawable/btn_radio"
            android:drawablePadding="20dp"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:text="@string/second"
            android:textSize="20dip" />
    </RadioGroup>
</RelativeLayout>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...