Android ListActivity - 固定页眉和页脚 [英] Android ListActivity - fixed header and footer

查看:40
本文介绍了Android ListActivity - 固定页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 ListActivity 中设置页眉和页脚固定在顶部和底部,这样只有内容(列表)在滚动,页眉和页脚也不在滚动?

Is it possible to set header and footer at ListActivity to be fixed at the top and the bottom, so only the content (list) is scrolling, not also header and footer?

我都这样设置:

View header = getLayoutInflater().inflate(R.layout.list_header, null);
View footer = getLayoutInflater().inflate(R.layout.list_footer, null);
ListView listView = getListView();
listView.addHeaderView(header);
listView.addFooterView(footer);

推荐答案

您可以通过使用自定义 XML 布局来实现它,您将在其中设置页眉、页脚和列表的布局.

You can achieve it by using a custom XML layout in which you will set the layout of your header, footer and list.

请注意,要与 ListActivity 兼容,此布局必须包含 ID 为 android.R.id.listListView:p>

Note that to be compatible with ListActivity this layout must contain a ListView with the id android.R.id.list:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="HEADER" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FOOTER" />

</LinearLayout>

并像这样在你的 ListActivity 中设置它:

And set it in your ListActivity like this:

public class TestActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

这篇关于Android ListActivity - 固定页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆