1.headerView布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:visibility="gone"
android:orientation="vertical"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
......
</LinearLayout>
</RelativeLayout>
2.获取headerView的布局
inflate = LayoutInflater.from(getApplicationContext()).inflate(R.layout.view_header, null);
3.在setAdapter前,添加headerView
listView.getRefreshableView().addHeaderView(inflate);
4.隐藏headerView布局
注意:根布局设置为GONE是无效的
container = inflate.findViewById(R.id.container);
container.setVisibility(View.GONE);
知识小补充
一直显示至底部,聊天专用:
listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
网友评论