现在我有这个布局(垂直线性布局内的水平相对布局),但我需要radiobuttons而不是复选框(用户必须只能选择一个选项)。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:orientation="horizontal">
<ImageView
android:src="@drawable/flag_en"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_alignParentLeft="true" />
<TextView
android:text="English"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dip"
android:textStyle="bold"
android:textSize="20dip"
/>
<CheckBox android:id="@+id/checkbox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:orientation="horizontal">
<ImageView
android:src="@drawable/flag_dk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_alignParentLeft="true" />
<TextView
android:text="Dansk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textStyle="bold"
android:textSize="20dip"
/>
<CheckBox android:id="@+id/checkbox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<Button
android:id="@+id/ang_btn"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="ang"
/>
</LinearLayout>
问题是RadioGroup必须放在线性布局内(不是相对的),所以我不能使用上面的布局。
我如何实现相同的布局(第三列中的多行,3列,无线电按钮),还可以使用无线电组和无线电按钮?
编辑:
我尝试了Robby Pond的解决方案(下面),我得到了这个:
我可以使用它,如果我可以在radiobutton和它的drawableLeft之间放一些空格。我设法在drawableLeft和文本之间用android:drawablePadding =“10dip”获得了一些空间(在我的上一个截图中没有看到)。
答案 0 :(得分:3)
使用单选按钮和单选按钮,并在RadioButton上使用android:drawableLeft作为图像。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioGroup ...>
<RadioButton ... android:drawableLeft="@drawable/flag_en" android:text="English" />
</RadioGroup>
</LinearLayout>