我正在使用微调器,用户可以选择他们的年龄,如下所示:
下拉箭头目前距离右侧太远。如何设置它以使微调器宽度仅与微调器项目内容一样短?
布局的微调部分的代码:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:text="Age:" />
<Spinner
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/input_age_spinner"
android:layout_weight="0.6" />
</LinearLayout>
我已经尝试将微调器布局宽度设置为wrap_content,但它没有做太多。我已经尝试将微调器layout_weight设置为0.2,这确实使它变窄,但在这种情况下它不再是左对齐
答案 0 :(得分:0)
试试这样:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Age:" />
<Spinner
android:id="@+id/input_age_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
(OR)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age:" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left" />
</LinearLayout>
</LinearLayout>
答案 1 :(得分:0)
data.table
答案 2 :(得分:0)
试试这个..
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Age:" />
<Spinner
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:id="@+id/input_age_spinner" />
</LinearLayout>