【发布时间】:2023-03-13 05:30:01
【问题描述】:
我有一个带有线性布局的滚动视图。在该线性布局中有一个列表视图。我遇到的问题是我的列表视图只有一定的空间,然后变得可滚动。我不希望这种情况发生。我希望显示整个列表。有谁知道我如何做到这一点?我试过使用这个链接,但是当我添加页脚时我的布局没有出现。 ListView in ScrollView potential workaround这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="vertical"
android:background="@drawable/darkimg"
android:weightSum="1">
<LinearLayout
android:id="@+id/numbersLL"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/round_rectangle"
android:layout_margin="4px"
android:paddingLeft="6px"
android:paddingTop="3px">
<TextView
android:id="@+id/numberPrint"
android:layout_height="wrap_content"
android:textSize="14px"
android:textStyle="bold"
android:textColor="@color/white"
android:layout_width="fill_parent"
android:text="@string/numberPrint">
</TextView>
<ListView
android:id="@+id/numberListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"></ListView>
</LinearLayout>
</LinearLayout>
</ScrollView>
这是我的页脚:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/formLL">
<TextView
android:id="@+id/numberFormTextViewt"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20px"
android:text="Add a number:"
android:textColor="@color/white" />
<Button
android:id="@+id/numberFormButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_add"></Button>
</LinearLayout>
这是将页脚添加到列表的 Java 代码:
LayoutInflater factory = getLayoutInflater();
LinearLayout numberFooter = (LinearLayout) factory.inflate(R.layout.number_form, null);
// List of numbers
numberListView = (ListView) this.findViewById(R.id.numberListView);
numberListView.addFooterView(numberFooter);
这里出了什么问题?显示活动时不显示页脚。我应该提到的一件事是页脚用于将项目添加到它上面的列表中。我不确定这是否会有所不同,但是当我测试它时,列表适配器是空的。甚至仍然应该显示页脚吗?任何帮助将不胜感激。
【问题讨论】:
-
这个 [LInk](blog.maxaller.name/2010/05/… ) 有完美的例子,只是看看....也检查这个问题...amongst us
-
感谢您的评论。我不确定这是否会对我有所帮助,因为我正在尝试使用不同页脚的多个 ListView。
-
等一下,我看到列表的高度是 0dp,所以它可能会起作用。不习惯相对布局,但我会试一试。
-
让我知道,以便我可以将其发布为答案...
-
我将以完全不同的方式来做这件事。通过更多研究,我意识到在滚动视图中使用 ListView 是不好的做法。
标签: android android-listview footer