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