效果图




类似格式,


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="wrap_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"        android:gravity="center"        android:textSize="12sp" />    <View        android:layout_width="1dp"        android:layout_height="match_parent"        android:background="#000" />    <TextView        android:id="@+id/unit"        android:layout_width="40dp"        android:layout_height="wrap_content"        android:gravity="center"        android:layout_gravity="center"        android:textColor="#000"        android:textSize="12sp" />    <View        android:layout_width="1dp"        android:layout_height="match_parent"        android:background="#000" />    <TextView        android:id="@+id/drugType"        android:layout_width="40dp"        android:layout_height="wrap_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/count"        android:layout_width="40dp"        android:layout_height="wrap_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/drugName"        android:layout_width="60dp"        android:layout_height="wrap_content"        android:layout_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 高度自适应代码 :

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, listView);listItem.measure(0, 0);totalHeight += listItem.getMeasuredHeight();}ViewGroup.LayoutParams params = listView.getLayoutParams();params.height = totalHeight+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));listView.setLayoutParams(params);}


冲突:

如果嵌套在ScrollView中使用 listView无法自适应的话 请在setAdapter之后在调用自适应方法。


如果大家有什么好的 实现表格方法除了recyclerview 请推荐 谢谢。。

更多相关文章

  1. android 2.2+ 完全退出程序的方法
  2. android 设置壁纸几种方法
  3. Android文件存储
  4. Anfdroid网络编程方法
  5. android 全面讲解BroadCastReceiver
  6. Android蓝牙开发浅析
  7. Android休眠唤醒机制简介(二)
  8. Android学习札记17:ImageView中的setImageBitmap()方法
  9. android输入法全屏问题

随机推荐

  1. Android(安卓)学习
  2. canvas 画一个圆上有 旋转角度 的直线
  3. android button 上添加图片
  4. Android(安卓)修改默认的ProgressBar的动
  5. Android(安卓)API demos 阅读笔记 1
  6. Layout属性介绍
  7. Android(安卓)maxLine属性导致android:im
  8. Mac与Android文件传输工具 Android(安卓)
  9. 【Android】SDK手动下载
  10. android之wifi体系架构源码流程分析