Android: Show listview between header and footer

浪尽此生 提交于 2019-12-20 04:38:12

问题


I learned from android dev tutorial and now I can make ListView. and it worked perfectly fine. Now my requirement is I want to show listview with a header and footer which I have made in xml file.

Basically on the top there will be a header & footer (a text view) and then follows listview scrollable between header and footer

Can someone forward me to the appropriate tutorial.


回答1:


Here is the tutorial links:

http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/

http://www.vogella.de/articles/AndroidListView/article.html

http://www.vogella.de/articles/AndroidListView/article.html#headerfooter




回答2:


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




回答3:


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>



回答4:


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>


来源:https://stackoverflow.com/questions/6924047/android-show-listview-between-header-and-footer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!