1.head(foot)View
通过给ListView添加各种head/foot可以实现各种自定义功能,主要用法如下(Kotlin):
//需要注意的是,只能添加布局,不能添加单个控件,比如Button
val headView = LayoutInflater.from(this).inflate(R.layout.item_head_blank, null) as LinearLayout
mLVOrderList.addHeaderView(headView)
//setAdapter一定要在添加布局之后
mLVOrderList.adapter = orderAdapter
用一段空白做个简单的例子:
<?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="20dp"
android:background="@color/colorInfoBg"
android:orientation="vertical">
//没有子控件时,height指定多少都不显示
</LinearLayout>
<?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="wrap_content"
android:background="@color/colorInfoBg"
android:orientation="vertical">
//这才是添加空白的正确姿势
<com.zhy.autolayout.AutoLinearLayout
android:layout_width="match_parent"
android:layout_height="20px"/>
</LinearLayout>