谁能告诉我我做错了什么? :(
我有 2 个 Spinner 和两个 TextView,我想将它们右对齐。
我已将所有内容设置为右侧,但所有内容仍然左对齐。
它是这样的:
但我也希望它看起来像这样:
这是我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="right"
android:gravity="right">
<RadioGroup
android:id="@+id/radios"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="center_horizontal"
android:inputType="text"
android:onClick="test"
android:orientation="horizontal"
android:paddingRight="10dp" >
<RadioButton
android:id="@+id/rbtn_sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:button="@null"
android:drawablePadding="3dp"
android:drawableRight="@android:drawable/btn_radio"
android:text="@string/label_sell_unicode"
android:textSize="12sp" />
<RadioButton
android:id="@+id/rbtn_rent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:drawablePadding="3dp"
android:drawableRight="@android:drawable/btn_radio"
android:text="@string/label_rent_unicode"
android:textSize="12sp"
android:paddingLeft="40dp"/>
</RadioGroup>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="right"
android:orientation="horizontal"
>
<TextView
android:id="@+id/textView_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_from"
/>
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:gravity="right"
android:layout_gravity="right"
android:spinnerMode="dropdown" />
<TextView
android:id="@+id/textView_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_to"
/>
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:gravity="right"
android:layout_gravity="right"
android:spinnerMode="dropdown" />
</LinearLayout>
更新:进行 ElDuderino 建议的更改后我的 XML。进行此更改后,两个 TextView 和两个 Spinner 消失了。他们不在屏幕上。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<RadioGroup
android:id="@+id/radios"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="center_horizontal"
android:inputType="text"
android:onClick="test"
android:orientation="horizontal"
android:paddingRight="10dp" >
<RadioButton
android:id="@+id/rbtn_sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:button="@null"
android:drawablePadding="3dp"
android:drawableRight="@android:drawable/btn_radio"
android:text="@string/label_sell_unicode"
android:textSize="12sp" />
<RadioButton
android:id="@+id/rbtn_rent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:drawablePadding="3dp"
android:drawableRight="@android:drawable/btn_radio"
android:text="@string/label_rent_unicode"
android:textSize="12sp"
android:paddingLeft="40dp"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
您在单选按钮上添加可绘制对象时犯了一个错误。试试这个,让我知道
android:drawableLeft="@android:drawable/btn_radio"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)