简体   繁体   中英

how to solve this scroll view error “ScrollView can host only one direct child”

<?xml version="1.0" encoding="utf-8"?>
<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/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ECEFF1"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity"
    tools:openDrawer="end">

<androidx.core.widget.NestedScrollView
    android:layout_width="match parent"
    android:layout_height="match parent">

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

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="65dp"
                android:background="#ED3733">

                <ImageView
                    android:id="@+id/homeScreenNavigation"
                    android:layout_width="40dp"
                    android:layout_height="60dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginLeft="10dp"
                    android:src="@drawable/ic_baseline_menu_24" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:src="@mipmap/ic_launcher_round" />

            </RelativeLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="30dp"
                android:layout_marginTop="30dp"
                android:text="Dashboard"
                android:textSize="40sp" />

            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="280dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="16dp"
                android:layout_marginRight="10dp"
                app:cardCornerRadius="8dp"
                app:cardElevation="8dp">

            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="280dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="16dp"
                android:layout_marginRight="10dp"
                app:cardCornerRadius="8dp"
                app:cardElevation="8dp">

            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="280dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="16dp"
                android:layout_marginRight="10dp"
                app:cardCornerRadius="8dp"
                app:cardElevation="8dp">

            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="280dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="16dp"
                android:layout_marginRight="10dp"
                app:cardCornerRadius="8dp"
                app:cardElevation="8dp">

            </androidx.cardview.widget.CardView>
        </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|left"
            app:menu="@menu/drawer_menu" />


    </androidx.core.widget.NestedScrollView>
</androidx.drawerlayout.widget.DrawerLayout>

Here "ScrollView can host only one direct child" I don't know how to solve this error can someone help me to solve this problem Thank you.................................,.....................................................................................................................................

ScrollView and NestedScrollView can have only one child you can use ConstraintLayout or other ViewGroup in ScrollView or NestedScrollView.

good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM