首页 > 解决方案 > 在横向模式下无法在屏幕底部看到 ListView

问题描述

我有一个 LinearLayoutandroid:id="@+id/content_frame"嵌套在 DrawerLayout 内android:id="@+id/drawer_layout"

在 LinearLayout 的顶部是 ImageViews、TextViews、Buttons、Switches 等。它们嵌套在一系列水平和垂直 LinearLayouts 中。到目前为止一切都很好。

在 LinearLayout 的底部是一个 ListView,它也嵌套在它自己的一个 LinearLayout 中。所以我的布局如下所示。(重力、填充等参数在下面删除以节省空间)。

在纵向方向上一切都很好,但是一旦我更改为横向,在许多设备上屏幕高度太小,无法在屏幕的下半部分看到我的 ListView。

我已经尝试将它全部包装在一个 ScrollView 中,但是我的 ListView 不会自动调整大小fill_parent并保持一个项目的高度,并且使用横向方向的 ScrollView 它根本不会让我滚动 ListView。

有人可以推荐一种方法让我在屏幕底部看到我的 ListView 并在纵向和横向模式下滚动它吗?

先感谢您!!

<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer_layout">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/content_frame"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="32dp"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <ImageView />

                    <ImageView />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <ImageView />

                </LinearLayout>

            </LinearLayout>

            <EditText />

            <Spinner />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button />

            <Button />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ProgressBar />

        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button />

            <Switch />

        </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <ListView
                    android:id="@+id/myTeamsListView"
                    android:layout_width="match_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:background="@drawable/spinner"
                    android:alwaysDrawnWithCache="true"
                    android:contentDescription="@string/myTeamsListViewcontent"
                    android:isScrollContainer="false"
                    android:scrollbars="none"
                    android:scrollingCache="false"
                    android:smoothScrollbar="false"></ListView>

            </LinearLayout>
        </LinearLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:onClick="onSwitchChange"
        app:headerLayout= "@layout/nav_header_main"
        app:menu="@xml/drawer_view" />

标签: listviewandroid-listviewandroid-xmlscreen-orientation

解决方案



推荐阅读