Monday, 15 June 2015

android - ListView layout_width match_parent and fill_parent not working inside of TableRow -



android - ListView layout_width match_parent and fill_parent not working inside of TableRow -

i using tablelayout , tablerow elements has listview inside. until load info in listview items in tablerow works fine. info has been loaded in listviews layout_width match_parent , fill_parent stops working.

note: in question asking layout_width issue. layout_height working great , don't have scrolling issue.

following xml of layout.

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/sv" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparentleft="true" android:layout_alignparenttop="true" > <tablelayout android:layout_width="match_parent" android:layout_height="wrap_content" > <tablerow android:id="@+id/tr_lbl_topsongs" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/app_orange" android:padding="5dp" > <textview android:id="@+id/tv_lbl_topsongs" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="top songs" android:textappearance="?android:attr/textappearancesmall" android:textcolor="@color/app_white" /> </tablerow> <tablerow android:id="@+id/tr_content_topsongs" android:layout_width="match_parent" android:layout_height="wrap_content" > <listview android:id="@+id/lv_topsongs" android:layout_width="match_parent" android:layout_height="wrap_content" > </listview> </tablerow> <tablerow android:id="@+id/tr_viewmore_topsongs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|center_vertical" android:background="@color/app_offwhite" android:gravity="center_horizontal|center_vertical" android:padding="5dp" > <textview android:id="@+id/tv_viewmore_topsongs" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="view more" android:textappearance="?android:attr/textappearancesmall" android:textcolor="@color/app_gray" /> </tablerow> <tablerow android:id="@+id/tr_lbl_topvideos" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/app_orange" android:padding="5dp" > <textview android:id="@+id/tv_lbl_topvideos" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="top videos" android:textappearance="?android:attr/textappearancesmall" android:textcolor="@color/app_white" /> </tablerow> <tablerow android:id="@+id/tr_content_topvideos" android:layout_width="match_parent" android:layout_height="wrap_content" > <listview android:id="@+id/lv_topvideos" android:layout_width="match_parent" android:layout_height="wrap_content" > </listview> </tablerow> <tablerow android:id="@+id/tr_viewmore_topvideos" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|center_vertical" android:background="@color/app_offwhite" android:gravity="center_horizontal|center_vertical" android:padding="5dp" > <textview android:id="@+id/tv_viewmore_topvideos" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="view more" android:textappearance="?android:attr/textappearancesmall" android:textcolor="@color/app_gray" /> </tablerow> <tablerow android:id="@+id/tr_lbl_topringtones" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/app_orange" android:padding="5dp" > <textview android:id="@+id/tv_lbl_topringtones" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="top ringtones" android:textappearance="?android:attr/textappearancesmall" android:textcolor="@color/app_white" /> </tablerow> <tablerow android:id="@+id/tr_content_topringtones" android:layout_width="match_parent" android:layout_height="wrap_content" > <listview android:id="@+id/lv_topringtones" android:layout_width="match_parent" android:layout_height="wrap_content" > </listview> </tablerow> <tablerow android:id="@+id/tr_viewmore_topringtones" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|center_vertical" android:background="@color/app_offwhite" android:gravity="center_horizontal|center_vertical" android:padding="5dp" > <textview android:id="@+id/tv_viewmore_topringtones" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="view more" android:textappearance="?android:attr/textappearancesmall" android:textcolor="@color/app_gray" /> </tablerow> </tablelayout> </scrollview>

update:

i have managed utilize listview within of scrollview next codes. registered touchlistner

lv_topsongs = (listview) rootview.findviewbyid(r.id.lv_topsongs); lv_topsongs.setontouchlistener(this);

my touchlistner in passing touch event scrollview , disabling touch on listview.

@override public boolean ontouch(view v, motionevent event) { v.getparent().requestdisallowintercepttouchevent(true); mscrollview.ontouchevent(event); homecoming false; }

i setting height after loading info in listview next code.

setlistviewheightbasedonchildren(lv_topsongs);

and setlistviewheightbasedonchildren function

/**** method setting height of listview dynamically. **** hack prepare issue of not showing items of listview **** when placed within scrollview ****/ public static void setlistviewheightbasedonchildren(listview listview) { listadapter listadapter = listview.getadapter(); if (listadapter == null) return; int desiredwidth = measurespec.makemeasurespec(listview.getwidth(), measurespec.unspecified); int totalheight = 0; view view = null; (int = 0; < listadapter.getcount(); i++) { view = listadapter.getview(i, view, listview); if (i == 0) view.setlayoutparams(new viewgroup.layoutparams(desiredwidth, layoutparams.wrap_content)); view.measure(desiredwidth, measurespec.unspecified); totalheight += view.getmeasuredheight(); } viewgroup.layoutparams params = listview.getlayoutparams(); params.height = totalheight + (listview.getdividerheight() * (listadapter.getcount() - 1)); params.width = layoutparams.match_parent; listview.setlayoutparams(params); listview.requestlayout(); }

screenshot

i solved problem assigning weight listview android:layout_weight="1".

still unable understand why have assign weight there 1 item in tablerow solved problem.

android android-listview

No comments:

Post a Comment