Android 对齐radioButton可拖动左上角
我想创建一个单选按钮,如下所示: 我在XML布局中使用的是android:drawableTop,但通过这种方式,drawable并不是水平向左对齐,而是居中对齐Android 对齐radioButton可拖动左上角,android,xml,android-layout,Android,Xml,Android Layout,我想创建一个单选按钮,如下所示: 我在XML布局中使用的是android:drawableTop,但通过这种方式,drawable并不是水平向左对齐,而是居中对齐 <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@android:drawable/btn_radio"
android:gravity="left"
android:button="@null"
android:text="RADIO 1"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RADIO 2"
android:button="@null"
android:gravity="center"
android:drawableTop="@android:drawable/btn_radio"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
我会告诉你一个简单的答案。但我认为这是有帮助的。同时拍摄两张图片和文本 编写一个选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checked_radiobutton" android:state_checked="true"/>
<item android:drawable="@drawable/unchecked_radiobutton" android:state_checked="false"/>
</selector>
将这两个单选按钮添加到可绘制文件中。然后在radiobutton中只需添加按钮标签即可
<RadioButton
android:id="@+id/lastvalue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/autochoose_radio"
android:checked="true"
android:gravity="center_vertical"
android:text="@string/lastvalue"
android:textSize="15sp" />
你不写任何东西来代替文本。我认为这是一个完美的解决方案。您能展示一下您的xml布局吗?谢谢您。你的意思是我必须把文字放在绘图表里面吗?那么它会被修复吗?但我如何以这种方式处理国际化?通常我会将radioButton文本放入strings.xml这样的文件中。。我认为在Radiobutton底部的文本是不可能的。如果你想,你必须遵循这个程序。