android: fill_parent of child view 填满屏幕

标签 android android-relativelayout fill-parent

我正在尝试复制微调器控件(请不要问为什么)我正在与分隔线作斗争。在我将分隔线添加到 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>

产生以下屏幕:

enter image description here

添加分隔符后,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>

产生以下屏幕:

enter image description here enter image description here 谁能发现我在这里做错了什么?...

最佳答案

为此,您应该使用九补丁图像,而不是使用多个 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/

相关文章:

Android 谷歌地图显示最接近当前位置的地理点

android - 使用 rxjava 对 android 应用程序进行单元测试

android - TextInput 和 launch_screen 文件中的relativelayout错误

android - "Workspace" subview 未在 Google "iosched"应用程序上填充高度

Android - EditText 多行强制填充高度

java - Android - 如何在代码中使 TextView fill_parent

android - 如何在 zoom android 中应用长按和捏合?

java - 安卓 p2p 连接

java - Android:将 View 放在与其他 View 相同的高度

java - 无法在 Java-Android 中两次设置背景属性(图像+颜色)