The ListView in Android is highly adaptive, resolving scrollview conflict issues as well as Android forms

Source: Internet
Author: User




Similar format,


Listview_item.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 "> <textview android:id=" @+id/tieshu "android:layout_width=" 40DP "android:layout_height=" WR        Ap_content "android:layout_gravity=" center "android:textcolor=" #000 "android:gravity=" center "        Android:textsize= "12SP"/> <view android:layout_width= "1DP" android:layout_height= "Match_parent"        android:background= "#000"/> <textview android:id= "@+id/usage" android:layout_width= "40DP" android:layout_height= "wrap_content" android:layout_gravity= "center" android:textcolor= "#000" and roid:gravity= "center" android:textsize= "12SP"/> <view android:layout_width= "1DP" Android:la Yout_height= "Match_parent" android:background= "#000"/> <textview android:id= "@+id/unit" android:layout_width= "40DP" and roid:layout_height= "wrap_content" android:gravity= "center" android:layout_gravity= "center" android:te Xtcolor= "#000" android:textsize= "12sp"/> <view android:layout_width= "1DP" android:layout_he ight= "Match_parent" android:background= "#000"/> <textview android:id= "@+id/drugtype" Androi D:layout_width= "40DP" android:layout_height= "wrap_content" android:layout_gravity= "center" android:te Xtcolor= "#000" android:gravity= "center" android:textsize= "12SP"/> <view Android:layout_widt H= "1DP" android:layout_height= "match_parent" android:background= "#000"/> <textview android: Id= "@+id/count" android:layout_width= "40DP" android:layout_height= "Wrap_content" Android:layout_gravi ty= "Center" AndroId:textcolor= "#000" android:gravity= "center" android:textsize= "12SP"/> <view android:layout _width= "1DP" android:layout_height= "match_parent" android:background= "#000"/> <textview and Roid:id= "@+id/drugname" android:layout_width= "60DP" android:layout_height= "Wrap_content" Android:layo    ut_gravity= "Center" android:gravity= "center" android:textcolor= "#000" android:textsize= "12SP"/> <view android:layout_width= "1DP" android:layout_height= "match_parent" android:background= "#000" /></linearlayout>


ListView Highly Adaptive Code:

public static void Setlistviewheightbasedonchildren (ListView listview) {ListAdapter ListAdapter = Listview.getadapter ( ); if (listadapter = = null) {return;} int totalheight = 0;for (int i = 0; i < Listadapter.getcount (); i++) {View ListItem = Listadapter.getview (i, NULL, list View); listitem.measure (0, 0); Totalheight + = Listitem.getmeasuredheight ();} Viewgroup.layoutparams params = Listview.getlayoutparams ();p arams.height = totalheight+ (Listview.getdividerheight () * (Listadapter.getcount ()-1)); Listview.setlayoutparams (params);}


Conflict:

If the ListView is not self-adaptive if nested in ScrollView Please call the Adaptive method after Setadapter.


If you have any good implementation of the table method in addition to Recyclerview please recommend thank you.

The ListView in Android is highly adaptive, resolving scrollview conflict issues as well as Android forms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.