---
title: "Android ListView的addHeaderView注意事项"
author: "dingran"
date: "2014-06-05T18:43:56Z"
tags: []
categories: ["移动开发"]
slug: "android-listview-addheaderview"
draft: false
lastmod: "2014-06-05T18:43:56Z"
id: 2076410
url: "https://dingran.iteye.com/blog/2076410"
---

Android ListView的addHeaderView注意事项


addHeaderView(heightView, null, false);

heightView这个view如果是从

View view = mInflater.inflate(R.layout.information_playdata_bottom, null);

layout文件转化过来的，那么这个布局文件必须是ViewGroup的根布局，例如LinearLayout或者
其他Layout，里面可以放置一些View.

如果图省事，比如想要heightView只是个不能选择的普通占位占高度的一个View，那么还是不能省事，应该在如此：

<?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" >

    <View
        android:layout_width="match_parent"
        android:layout_height="30dip" />

</LinearLayout>