Android ListView setting height -
we have android application listview, containing n items. setting height of listview component, use method:
public static void setlistviewheightbasedonchildren(listview listview) { listadapter listadapter = listview.getadapter(); if (listadapter == null) { return; } int totalheight = 0; int desiredwidth = view.measurespec.makemeasurespec(listview.getwidth(), view.measurespec.at_most); (int = 0; < listadapter.getcount(); i++) { view listitem = listadapter.getview(i, null, listview); listitem.measure(desiredwidth, view.measurespec.unspecified); totalheight += listitem.getmeasuredheight(); } viewgroup.layoutparams params = listview.getlayoutparams(); params.height = totalheight + (listview.getdividerheight() * (listadapter.getcount() - 1)); listview.setlayoutparams(params); listview.requestlayout(); }
the height measured bad in first run. if method called later (e.g. after reloading listview data becouse of change), height correct.
it seems problem in
int desiredwidth = view.measurespec.makemeasurespec(listview.getwidth(), view.measurespec.at_most);
where value desiredwidth -2147483648 after first call, -2147483368 after other calls , height set correctly.
is there way change behaviour , height correctly in first call?
Comments
Post a Comment