gpt4 book ai didi

Android ListActivity - 固定页眉和页脚

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:04 26 4
gpt4 key购买 nike

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

我都是这样设置的:

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 布局来实现它,您将在其中设置页眉、页脚和列表的布局。

请注意,要与 ListActivity 兼容,此布局必须包含一个 ListView 和 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 中设置它:

public class TestActivity extends ListActivity {

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

关于Android ListActivity - 固定页眉和页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13401760/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com