开发者

Android: Show listview between header and footer

I learned from android dev tutorial and now I can make ListView. and it worked perfectly fine. Now my re开发者_如何转开发quirement 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.


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


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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜