简体   繁体   中英

Match_parent height inside layout with wrap_content height

I'm trying to cover my entire list item with a shadow drawable on the right side.

Problem is that my layout wrapping the drawable has not a constant height. I tired to set my drawable to align parent top and align parent bottom but it still does not stretch the entire height of its parent layout.

look att the shadow on the right (I've provided a min height property to make it visible, the forth list item is bigger than min view, and the shadow does not stretch)

在此输入图像描述

Source:

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

    <include layout="@layout/list_item_header" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/img_news_thumb"
            android:layout_width="@dimen/listview_one_row"
            android:layout_height="@dimen/listview_one_row"
            android:scaleType="centerCrop"
            android:src="@drawable/default_news_thumb" />

        <TextView
            android:id="@+id/txt_news_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_marginLeft="@dimen/space_m"
            android:layout_marginTop="@dimen/space_s"
            android:layout_toRightOf="@+id/img_news_thumb"
            android:ellipsize="marquee"
            android:paddingRight="@dimen/space_m"
            android:singleLine="false"
            android:text="Title"
            android:textSize="14sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/txt_news_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_below="@+id/txt_news_title"
            android:layout_marginBottom="0dp"
            android:layout_marginLeft="@dimen/space_m"
            android:layout_marginTop="@dimen/space_s"
            android:layout_toRightOf="@+id/img_news_thumb"
            android:ellipsize="end"
            android:paddingRight="@dimen/space_m"
            android:singleLine="true"
            android:text="Date"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/font_light" />

        **<ImageView
            android:id="@+id/img_news_list_shadow"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/img_news_thumb"
            android:minHeight="@dimen/listview_one_row"
            android:scaleType="fitXY"
            android:src="@drawable/list_shadow_r" />**

        <ImageView
            android:id="@+id/img_selected_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:scaleType="fitXY"
            android:src="@drawable/list_item_arrow"
            android:visibility="gone" />
    </RelativeLayout>

    <include layout="@layout/list_item_devider" />

</LinearLayout>

发现它是不可能的,因为父布局,即在这种情况下的线性布局总是在列表视图中使用时包装内容。

Due to recent investigations, i've found out that the answer is much simpler than that.

When inflating the layout, we should use this:

View rowView = inflater.inflate(R.layout.row_layout, parent, false);

Instead of the commonly used error:

View rowView = inflater.inflate(R.layout.row_layout, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM