我正在尝试复制微调器控件(请不要问为什么)我正在与分隔线作斗争。在我将分隔线添加到 ImageView 的左侧之前,假微调器看起来很好。添加分隔线后,它的高度会填满屏幕的剩余部分。有人可以解释一下吗?
以下 xml:
.......
<Spinner
android:id="@+id/equipment_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<ImageView
android:id="@+id/spinner_arrow"
android:layout_width="45sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/spinner_arrow"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
产生以下屏幕:
添加分隔符后,xml 如下所示:
<Spinner
android:id="@+id/equipment_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<ImageView
android:id="@+id/spinner_arrow"
android:layout_width="45sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/spinner_arrow"/>
<View
android:background="#e7ebe7"
android:layout_width="1dip"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/spinner_arrow"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
产生以下屏幕:
谁能发现我在这里做错了什么?...
最佳答案
为此,您应该使用九补丁图像,而不是使用多个 View 。这就是默认的微调器所做的。我不知道你为什么要创建一个新的微调器,但如果你保持视觉效果不变,你可以重复使用内置图像。
android.R.layout.simple_spinner_item
是您可以重复使用的 TextView 布局。或者,您可以直接获取背景:android.R.drawable.btn_dropdown
,这是一个 XML 选择器,每个状态都有位图。 Android 源代码中提供了更多详细信息。
关于android: fill_parent of child view 填满屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7003314/