android - 在 ScrollView 中列出

标签 android list scroll scrollview

在我的屏幕上有一个 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/

相关文章:

android - Flutter Android Build Failed : com. android.tools.r8.CompilationFailedException: 编译未能完成

android - 具有透明背景的渐变描边

java - 字符串列表中单词的频率

vb.net - 我需要将滚动属性添加到面板控件中的标签控件

android - Android Studio 更新后 ProGuard 无法正常工作

java - 在 Android 中使用正则表达式解析

c++ - 查找哪个元素未在列表中排序

c++ - 更新元素 STL 列表列表

JavaFX TextArea 获取scrollTop百分比

释放包含滚动 UITableView 的 View Controller 时,iPhone 应用程序崩溃