【问题标题】:Radio Button and text view layout单选按钮和文本视图布局
【发布时间】:2016-05-24 23:08:53
【问题描述】:
我想要布局左侧的文本视图和右侧的单选按钮。但是当我运行我的代码时,它只在右侧显示 textview 和 radiobutton。
以下是我的 xml 文件。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/tvAnswer1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<RadioButton
android:id="@+id/rbAnswer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
【问题讨论】:
标签:
android-layout
android-studio
radio-button
【解决方案1】:
试试这个
使用具有权重属性的线性布局,这也有助于设备设计兼容性
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="5" >
<TextView
android:id="@+id/tvAnswer1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="asfafasf"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="@+id/rbAnswer1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio" />
</LinearLayout>
【解决方案2】:
使用这个。
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="@+id/tvAnswer1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<RadioButton
android:id="@+id/rbAnswer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:llayout_toRightOf="@+id/tvAnswer1"
/>
可以,您的单选按钮位于 TextView 的右侧。