android - RecyclerView list item view does not consistently use all height when using "match_parent" -


similar cardview layout_width="match_parent" not match parent recyclerview width i'm trying layout_height="match_parent" working.

i trying reproduce gridview's drawselectorontop recyclerview.

my list item's simplified xml is:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"                 android:id="@+id/menu_category_adapter_item_row"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:minheight="?android:listpreferreditemheight">      <textview         android:id="@+id/menu_category_adapter_item_title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textcolor="@color/text_color_main"/>      <view         android:id="@+id/menu_category_adapter_item_selector"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:background="@drawable/bg_list_item"         android:clickable="true"/>  </relativelayout> 

the code inflating layout is:

return new viewholder(layoutinflater.from(parent.getcontext())         .inflate(r.layout.menu_category_adapter_item, parent, false)); 

selector drawable bg_list_item.xml is:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_pressed="true" android:drawable="@drawable/bg_list_item_pressed"/>     <item android:state_selected="true" android:drawable="@drawable/bg_list_item_selected"/>     <item android:drawable="@drawable/bg_list_item_normal"/> </selector> 

drawable bg_list_item_pressed.xml is:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android">     <solid android:color="#3000"/> </shape> 

if hard code height e.g. layout_height="32dp" selector view, selector shown items can change height can't hard code workaround.

i have tried using layout_alignparenttop , layout_alignparentbottom no luck.

something strange note inconsistently works. on grid of 8 items (2 rows of 4 items), items 1, 3 , 4 show selector.

you can setlayoutparams recyclerview's child view


Comments