Last row of expandable listview not full view in android -
here uses view , there code per given below.
<linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <tablerow android:id="@+id/tab_stone_info" android:layout_width="match_parent" android:layout_height="30dp" android:layout_margintop="1dp" android:background="@color/stylebreaktabcolor" android:weightsum="9"> <textview android:id="@+id/stone_type" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/type" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> <textview android:id="@+id/stone_shape" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/shape" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> <textview android:id="@+id/stone_qlty" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/quality" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> <textview android:id="@+id/stone_grade" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/grade" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> <textview android:id="@+id/stone_qty" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/qty" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> <textview android:id="@+id/stone_wt" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/wt" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> <textview android:id="@+id/stone_mmsize" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/mmsize" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> <textview android:id="@+id/stone_setting" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/setting" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> <textview android:id="@+id/stone_settmode" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/cell_shape" android:gravity="center" android:text="@string/settingmode" android:textcolor="@color/txtstylebreakup" android:textsize="12sp" /> </tablerow> <relativelayout android:id="@+id/layout_tab_stone_info_value" android:layout_width="match_parent" android:layout_height="match_parent" > <com.mindtech.expandableheightlistview android:id="@+id/listviewstone" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="#00000000" android:gravity="center" android:horizontalspacing="2dp" android:isscrollcontainer="false" android:stretchmode="columnwidth" android:verticalspacing="20dp" /> </relativelayout> </linearlayout>
and uses epandablelistview below class.
public class expandableheightlistview extends listview { boolean expanded = false; public expandableheightlistview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); } public expandableheightlistview(context context) { super(context); } public expandableheightlistview(context context, attributeset attrs) { super(context, attrs); } public boolean isexpanded() { return expanded; } @override public void onmeasure(int widthmeasurespec, int heightmeasurespec) { // int expandspec = measurespec.makemeasurespec(integer.max_value >> 2, // measurespec.at_most); // // super.onmeasure(widthmeasurespec, expandspec); // int heightmeasurespec_custom = measurespec.makemeasurespec( // integer.max_value >> 2, measurespec.at_most); // super.onmeasure(widthmeasurespec, heightmeasurespec_custom); // viewgroup.layoutparams params = getlayoutparams(); // params.height = getmeasuredheight(); if (isexpanded()) { int expandspec = measurespec.makemeasurespec(measured_size_mask, measurespec.at_most); super.onmeasure(widthmeasurespec, expandspec); viewgroup.layoutparams params = getlayoutparams(); params.height = getmeasuredheight(); } else { super.onmeasure(widthmeasurespec, heightmeasurespec); } } public void setexpanded(boolean expanded) { this.expanded = expanded; } }
i refer question did not correct. grid of images inside scrollview
the main problem occur when first row height not biger second or other. if row content length same no issues.
it looks getting layoutparams listview, modifying height parameter, never calling setlayoutparams tell view use modified height. try this:
if (isexpanded()) { int expandspec = measurespec.makemeasurespec(measured_size_mask, measurespec.at_most); super.onmeasure(widthmeasurespec, expandspec); viewgroup.layoutparams params = getlayoutparams(); params.height = getmeasuredheight(); //add line setlayoutparams(params); }
also, i've ran problems in past onmeasure() method, not measured when framework calls method. might try viewtreeobserver, can register listener notified when full view laid out, this:
final linearlayout layout = (linearlayout) findviewbyid(r.id.layout_id); viewtreeobserver vto; if (layout != null) { vto = layout.getviewtreeobserver(); vto.addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() { @override public void ongloballayout() { layout.getviewtreeobserver().removeongloballayoutlistener(this); //modify layoutparams here } }); }
Comments
Post a Comment