[英]How to add a Footer View (TextView) to the end of a 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之间的部分应该可以滚动
这是我的代码,除了txtViewFooter以外,它都起作用,如果列表足够短,无法容纳一部分屏幕,则会显示txtViewFooter。 但如果列表较长且重新编排时不显示
<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);
在将其他项目添加到列表之前,请确保添加页脚或页眉View
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.