Android ListView常用小技巧汇总

2019-12-10 18:37:36王振洲

相关布局 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
  xmlns:tools="http://www.easck.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

  <LinearLayout
    android:id="@+id/operator_ll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button
      android:id="@+id/add_btn"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:gravity="center"
      android:text="添加" />

    <Button
      android:id="@+id/del_btn"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:gravity="center"
      android:text="删除" />
  </LinearLayout>

  <ListView
    android:id="@+id/test_lv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="#d1d1d1"<!--分隔线颜色-->
    android:dividerHeight="1px"<!--分隔线高度-->
    android:listSelector="@android:color/transparent"<!--取消默认点击效果-->
    android:scrollbars="none"><!--隐藏滚动条-->
    </ListView>

  <ImageView
    android:id="@+id/empty_iv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="100dp"
    android:src="@mipmap/empty"
    android:visibility="gone" />

</LinearLayout>

activity_type.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
  xmlns:tools="http://www.easck.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">


  <ListView
    android:id="@+id/type_lv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ></ListView>


</LinearLayout>