java - GridView.minHeight does not work for small item counts -
i use markup:
<gridview android:id="@+id/gvblock0" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/solitude" android:gravity="center" android:minheight="120dp" android:numcolumns="2" android:stretchmode="columnwidth" tools:layout_height="120dp" tools:listitem="@layout/list_item_block"/>
if have 3 items (40dp height per row) have 2 rows , 80dp height. if change android:layout_height=120dp
, have 120dp height expected.
but want use minheight. why doesn't work?
from gridview
source code, seems not support minheight
attribute.
you can fix 1 of following:
1) create minheightgridview
custom class extends gridview
, fix issue adding following override code example:
@override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { super.onmeasure(widthmeasurespec, heightmeasurespec); // after gridview measured everything, see if height needs update int desiredheight = getmeasuredheight(); desiredheight = math.max(desiredheight, getsuggestedminimumheight()); setmeasureddimension(getmeasuredwidth(), desiredheight); }
2) encapsulate gridview
inside container view - container view have minheight
. make sure set background , gravity needed on container view, example:
<framelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/solitude" android:minheight="120dp"> <gridview android:id="@+id/gvblock0" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:numcolumns="2" android:stretchmode="columnwidth" tools:layout_height="120dp" tools:listitem="@layout/list_item_block"/> </framelayout>
Comments
Post a Comment