首页 > 解决方案 > 如何在滚动视图中显示两个列表视图

问题描述

我查看了多个示例,我也知道这不是好的做法,但是有没有人可以帮助我解决这个问题。我的第一个列表显示正确,但我的第二个列表已折叠并有自己的滚动视图。我想为整个页面而不是单个列表视图提供滚动视图。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".EtsiActivity">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginBottom="?android:attr/actionBarSize">>

        <TextView
            android:layout_height="20dp"
            style="?android:attr/listSeparatorTextViewStyle"
            android:text="ETSI ERROR COUNT"
            android:id="@+id/StatusHeader"
            android:textColor="@color/primary"
            android:layout_marginTop="5dip"
            android:layout_marginLeft="5dp" />


            <ListView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/etsiStatus"
                android:layout_below="@+id/StatusHeader"
                android:gravity="center_horizontal">
            </ListView>

        <TextView
            android:layout_height="20dp"
            style="?android:attr/listSeparatorTextViewStyle"
            android:text="TS MAP"
            android:id="@+id/TSHeader"
            android:textColor="@color/primary"
            android:layout_marginTop="5dip"
            android:layout_marginLeft="5dp"
            android:layout_below="@id/etsiStatus"/>

            <ListView android:id="@+id/TSList"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/TSHeader"
                android:gravity="center_horizontal"
                />

        </LinearLayout>
    </ScrollView>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_navigation_menu"
        android:background="?android:attr/windowBackground" />

</RelativeLayout>

标签: androidxml

解决方案


我相信aNestedScrollView是你想要的。看看Android:ScrollView vs NestedScrollView


推荐阅读