在我的屏幕上有一个 ListView 和一个按钮。我的 list 有 8 项。如果这两个项目不适合,我希望我的屏幕滚动。我不希望我的列表滚动,但包括列表和按钮在内的完整布局。如果我使用下面的布局,它只显示在列表中的项目上,我必须在列表中滚动才能转到下一个项目。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@android:id/list"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="@drawable/round_background" />
<Button android:text="Search" android:id="@+id/carSearchButton"
android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
最佳答案
您不能将 ListView 放在 ScrollView 中。 GridView,或任何处理与 ScrollView 在同一轴上滚动的 View 。这样框架就不知道哪个 View 应该处理滚动事件。此布局在编译时不会产生错误,但无法正常工作。
你应该在这里做什么:转储外部 ScrollView,你不需要它。只使用 ListView,然后使用 .addFooter() 将按钮添加到 ListView,这是最简单的方法。这样您的按钮将显示为列表元素,但您不必随意使用自定义适配器。
关于android - 在 ScrollView 中列出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4000092/