Match_parent match height inside layout with wrap_content height

I am trying to cover my entire list item with a shadow pattern on the right side.

The problem is that my layout wrapping drawable does not have a constant height. I'm tired of setting my drawable to align the parent top and align the parent bottom, but it still does not stretch the entire height of its parent layout.

Look at the shadow on the right (I provided the min height property to make it visible, the fourth list item is larger than min, and the shadow does not stretch)

enter image description here

A 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> 
+4
source share
2 answers

Due to recent research, I found out that the answer is much simpler.

When inflating the layout, we should use this:

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

Instead of a commonly used error:

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

This was found to be impossible, since the parent layout, i.e. linear layout, in this case always wraps the content when it is used in the list.

+1
source

All Articles