как решить эту ошибку просмотра прокрутки «ScrollView может содержать только одного прямого дочернего элемента»

#java #android #xml #android-recyclerview #scrollview

#java #Android #xml #android-recyclerview #scrollview

Вопрос:

 <?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>
 

Здесь «ScrollView может содержать только одного прямого дочернего элемента»
Я не знаю, как решить эту ошибку, может кто-нибудь помочь мне решить эту проблему
Спасибо……………………………,…………………………………………………………………………………………………………………….

Комментарии:

1. Поскольку в ошибке указано, что вид прокрутки должен иметь только одного прямого дочернего элемента, но иметь LinearLayout и затем NavigationView . Либо переместите NavigationView внутрь LinearLayout , либо из ScrollView

Ответ №1:

ScrollView и NestedScrollView могут иметь только одного дочернего элемента. вы можете использовать ConstraintLayout или другую ViewGroup в ScrollView или NestedScrollView.

удачи.