ListView 在 Android 7.1.1 上不滚动

ListView not scrolling on Android 7.1.1

我正在尝试在 Android 7.1.1 设备上部署 ListView 应用程序。列表视图包含的项目足以超过屏幕的大小。到目前为止我尝试过的任何 layouting/code 组合都失败了 - 设备上没有执行滚动。

这是最新的布局摘录:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/list_view"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:scrollbarSize="3dp"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical"
        android:scrollingCache="true"
        android:smoothScrollbar="true" />
</LinearLayout>

如有任何提示,我们将不胜感激。

编辑:列表视图由 android.widget.ArrayAdapter 和 android.R.layout 构建。simple_list_item_activated_1 项目布局:

itemsList = findViewById(R.id.list_view);
itemsList.setAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_activated_1, new ArrayList<>(...items...)));
itemsList.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

提示 1:使用 match_parent 而不是 fill_parent

技巧 2:使用 RecyclerView。它比 ListView 更灵活、更现代。

提示 3:如果只有一个视图,则不需要 LinearLayout。

希望这些提示中的一些可以解决您的问题。