Get the height of dynamically added LinearLayouts in Android -
i working in android application , adding linear layout dynamically in scollview. want height of each linear layout added dynamically . below code , xml.
linearlayout layout = (linearlayout) findviewbyid(r.id.subscrolllinearlayout); layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service); list<string> msemplog = new arraylist<string>(); msemplog.add("test1"); msemplog.add("test2"); msemplog.add("test3"); msemplog.add("test4"); msemplog.add("test5"); msemplog.add("test6"); msemplog.add("test7"); msemplog.add("test8"); (int = 0; < msemplog.size(); i++) { linearlayout service_row = (linearlayout) inflater.inflate( r.layout.tesffff, null); textview dd = ((textview) service_row.findviewbyid(r.id.test1)); dd.settext(msemplog.get(i)); dd.settag(i); ((textview) service_row.findviewbyid(r.id.test2)).settext(msemplog .get(i)); layout.addview(service_row, i); } scrollview parentscrollview = (scrollview) findviewbyid(r.id.parentscroll); scrollview childscrollview = (scrollview) findviewbyid(r.id.subscroll); parentscrollview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { findviewbyid(r.id.subscroll).getparent() .requestdisallowintercepttouchevent(false); return false; } }); childscrollview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { // disallow touch request parent scroll on touch of // child view v.getparent().requestdisallowintercepttouchevent(true); return false; } }); }
xml
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/parentscroll" android:layout_width="match_parent" android:layout_height="match_parent" android:fillviewport="true" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <scrollview android:id="@+id/subscroll" android:layout_width="match_parent" android:layout_height="200dp" > <linearlayout android:id="@+id/subscrolllinearlayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > </linearlayout> </scrollview> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> <textview android:id="@+id/test1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="dfsdfsdf" /> </linearlayout> </scrollview>
row xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:padding="15dp" android:weightsum="2" > <textview android:id="@+id/test1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:clickable="true" android:onclick="ontest1" android:textcolor="@android:color/black" /> <textview android:id="@+id/test2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:gravity="center" android:onclick="ontest2" android:textcolor="@android:color/black" /> </linearlayout>
this worked me
mylistviewobj.post(new runnable(){ public void run(){ int height = mylistviewobj.getheight(); } });
Comments
Post a Comment