Android: Show listview between header and footer

浪子不回头ぞ 提交于 2019-12-02 04:03:01
Täg

You may need to add in your xml two TextViews. One before your ListView, the other one, right under the ListView.

here comes a snippet for the ListView with header+footer;

<LinearLayout android:id="@+id/lay_listitems"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:background="@drawable/white"
                >

                <TextView android:id="@+id/listview_items_header"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/text_size_large"
                    android:textStyle="normal"
                    android:gravity="center_horizontal"
                    android:textColor="@drawable/titlecolor"
                    android:singleLine="true"
                    android:visibility="visible"
                    android:text=" --- HEADER ---"
                    />
                <ListView android:id="@+id/listview_items"
                    android:layout_width="match_parent" 
                    android:layout_height="match_parent"
                    android:drawSelectorOnTop="false"
                    android:smoothScrollbar="true"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:clickable="true"
                    android:dividerHeight="1dip"
                    android:divider="@drawable/ltgray"
                    android:layout_gravity="center"
                    android:gravity="center"
                    />

                <TextView android:id="@+id/listview_items_footer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/text_size_large"
                    android:textStyle="italic"
                    android:gravity="center_horizontal"
                android:textColor="@drawable/normaltextcolor"
                android:singleLine="true"
                android:visibility="visible"
                android:text=" --- FOOTER --- "
                    />
            </LinearLayout>

p.s. as an extra, custom colors can be added into colors.xml as below

<drawable name="titlecolor">#83a4cd</drawable>
<drawable name="normaltextcolor">#83a4cd</drawable>
<drawable name="gray">#585858</drawable>
<drawable name="ltgray">#BDBDBD</drawable>
<drawable name="extraltgray">#F2F2F2</drawable>

This may be late but hope this may help someone. :-)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView
        android:text="Header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <ListView
        android:id="@android:id/listview1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
    <TextView
        android:text="Footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_gravity="bottom"/>
</LinearLayout>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!