0

我无法使 aView填充 a 的高度RelativeLayout,这是ListView项目的布局。这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<View 
    android:id="@+id/fill_the_height_please"
    android:layout_width="15dp"
    android:layout_height="match_parent"
    android:background="@color/red"/>

<TextView
    android:id="@+id/delivery_list_item_dest"
    android:layout_width="wrap_content"
    android:layout_toRightOf="@id/fill_the_height_please"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="2dp"
    android:text="Destinatario" />

<TextView
    android:id="@+id/delivery_list_item_address"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/delivery_list_item_dest"
    android:layout_below="@id/delivery_list_item_dest"
    android:layout_marginTop="5dp"
    android:layout_marginRight="5dp"
    android:text="Location" />

<ImageButton
    android:id="@+id/delivery_list_item_mapBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="0dp"
    android:src="@drawable/map_location"
    android:background="@null" />

id为fill_the_height_的视图请不要填充项目高度。在下图中,您可以看到结果(没有显示):

在此处输入图像描述

我想要这样的东西:

在此处输入图像描述ü

我也尝试如下更改视图布局,但无论如何都不起作用:

<View 
    android:id="@+id/fill_the_height_please"
    android:layout_width="15dp"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:background="@color/red"/>

请问你能帮助实现我的目标吗?谢谢你。

4

3 回答 3

2

一种建议是将 layout_alignTop="@+id/delivery_list_item_mapBtn" 和 layout_alignBottom="@+id/delivery_list_item_mapBtn" 添加到视图并使其始终适合图像高度。

于 2014-05-26T09:01:45.483 回答
1

这里,它似乎RelativeLayout在 17 及更低版本中有一个错误。所以我改变了我的布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<View 
    android:id="@+id/fill_the_height_please"
    android:layout_width="15dp"
    android:layout_height="match_parent"
    android:background="@color/red"/>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/delivery_list_item_dest"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Destinatario"
            android:layout_marginBottom="5dp" />

        <TextView
            android:id="@+id/delivery_list_item_address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Location" />
    </LinearLayout>

    <ImageButton
        android:id="@+id/delivery_list_item_mapBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="0dp"
        android:src="@drawable/map_location"
        android:background="@null" />

</RelativeLayout>

有点复杂,但有效。但是,如果有人仅使用RelativeLayout

于 2014-05-26T09:40:07.660 回答
1

尝试改变

android:layout_toRightOf="@id/delivery_list_item_statusBtn"

android:layout_toRightOf="@id/fill_the_height_please"

您没有 delivery_list_item_statusBtn。但即使不改变这一点,我也会看到红色部分。试试看,如果没有帮助,请发布适配器的代码。

于 2014-05-26T09:03:32.323 回答