1.header.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=”wrap_content”>
    <LinearLayout android:layout_width=”match_parent”
        android:layout_height=”wrap_content” android:background=”@drawable/recordlist_top”>
    </LinearLayout>
    </LinearLayout>

2.footer.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=”wrap_content”>
    <LinearLayout android:layout_width=”match_parent”
        android:layout_height=”wrap_content” android:background=”@drawable/recordlist_top”>
    </LinearLayout>
    </LinearLayout>

 

3.Listview.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=”wrap_content”
    android:orientation=”vertical”>
    <ListView android:id=”@+id/text_fontstyle_lv”
        android:layout_height=”match_parent” android:layout_width=”match_parent”
        android:textColor=”@android:color/white” android:divider=”@drawable/recordlist_splitline”
        android:dividerHeight=”1px” android:cacheColorHint=”#00000000″></ListView>
</LinearLayout>

 

4.动态添加header和footer到listview中

View listheader = LayoutInflater.from(getContext()).inflate(
                R.layout.header, null);
        View listfooter = LayoutInflater.from(getContext()).inflate(
                R.layout.footer, null);
        list.addHeaderView(listheader);
        list.addFooterView(listfooter);

        list.setAdapter(mAdapter);

5.最后的效果图

dropdown