Add more ListView inside one page layout Android -
i dont know add more listview inside 1 page layout (attach picture)
i want each listview not scrolling. page layout scrolling only. me!! build same home layout app: https://play.google.com/store/apps/details?id=com.google.android.youtube
answer had resolve problem step1: make new file java:
public class expandableheightlistview extends listview { boolean expanded = false; public expandableheightlistview(context context) { super(context); } public expandableheightlistview(context context, attributeset attrs) { super(context, attrs); } public expandableheightlistview(context context, attributeset attrs,int defstyle) { super(context, attrs, defstyle); } public boolean isexpanded() { return expanded; } @override public void onmeasure(int widthmeasurespec, int heightmeasurespec) { // hack! take android! if (isexpanded()) { // calculate entire height providing large height hint. // not use highest 2 bits of integer; // reserved measurespec mode. int expandspec = measurespec.makemeasurespec(integer.max_value >> 2, 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; } }
step2: java: replace listview ->expandableheightlistview, , set listview.setexpanded(true);
step3: layout xml: replace
<yourpackage.expandableheightlistview android:id="@+id/etresponse" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="300dp" android:scrollbars="none" android:orientation="vertical" android:fadingedge="none"> </yourpackage.expandableheightlistview>
step4: done!
you can calculate height of listview belong number item in this. here example :
public class expandedlistview extends listview { private android.view.viewgroup.layoutparams params; private int old_count = 0; public expandedlistview(context context, attributeset attrs) { super(context, attrs); } @override protected void ondraw(canvas canvas) { if (getcount() != old_count) { old_count = getcount(); params = getlayoutparams(); if (getchildat(0)!= null){ params.height = getcount() * (old_count > 0 ? (getchildat(0).getheight()) : 0) ; }else params.height = 0; setlayoutparams(params); requestlayout(); } super.ondraw(canvas); } }
and use in xml :
....... <your package.expandedlistview android:id="@+id/lv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none" /> <your package.expandedlistview android:id="@+id/lv2" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none" /> ....
Comments
Post a Comment