本文介绍了如何在页脚视图(TextView的)添加到ListView的结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做这样的布局:

actionbar
====================
txtViewTitle
--------------------
listview item1
listview item2
listview item3
........scroll scroll scroll
...at the end of all the items:
-----------------
txtViewFooter
==================
linearlayout of buttons [always visible at the bottom]
-------------------------------

在========== S之间的部分应该是滚动

the part between the ==========s should be scrollable

这是我的code,它的工作原理除了列表是否足够短,在屏幕的部分,以适应所显示txtViewFooter。但是,如果列表较长,不显示requores scroling

here's my code, it works except for txtViewFooter which is displayed if the list is short enough to accomodate in part of the screen. but not displayed if list is longer and requores scroling

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/d_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
    android:id="@+id/txtViewTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="8dp"
    android:background="#eeeeee"
    android:gravity="center|center"
    android:layout_alignParentTop="true"
    style="?android:listSeparatorTextViewStyle"/>

<View
    android:layout_width="fill_parent"
    android:layout_height="0.1dp"
    android:layout_below="@+id/txtViewTitle"
    android:id="@+id/separator"
    android:visibility="visible"
    android:background="@android:color/darker_gray"/>

<ListView
android:layout_height="match_parent"
android:layout_below="@+id/separator"
android:id="@+id/my_list"
android:listSelector="@android:color/transparent"
android:smoothScrollbar="true"
android:layout_width="fill_parent"
android:background="@android:color/transparent"
    android:textColor="#000000"
    android:dividerHeight="0dp"
    android:cacheColorHint="@android:color/transparent">
</ListView>

<TextView
    android:id="@+id/txtViewFooter"
    android:layout_below="@+id/my_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp"
    android:textStyle="italic"
    />

<View
android:layout_width="fill_parent"
android:layout_height="0.1dp"
android:layout_above="@+id/bottom_menu"
android:id="@+id/separator2"
android:visibility="visible"
android:background="@android:color/darker_gray"/>

<LinearLayout android:id="@+id/bottom_menu"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true"
    android:background="#eeeeee">
    <include layout="@layout/footer_menu" />
</LinearLayout>

推荐答案

使用

ListView.addFooterView(View v)

到页脚添加到您的的ListView 。您不需要定义页脚的.xml

例如:

TextView tv = new TextView(Context);
tv.setText("I am a footer")

ListView.addFooterView(tv);

这是充气的.xml:

View footer = LayoutInflater.from(Context).inflate(R.layout.your_footer_layout, null);
ListView.addFooterView(footer);

请确保您添加标题或注脚查看 之前添加其他项目到列表中。

Make sure you add your footer or header View before you add other items to the list.

这篇关于如何在页脚视图(TextView的)添加到ListView的结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 08:05