Если Интернет отключен, возникает ошибка java.lang.IllegalStateException: ScrollView может содержать только один прямой дочерний элемент - PullRequest
0 голосов
/ 14 октября 2019

Я использую NestedScrollView с одним макетом, но они выдают ошибку, как показано ниже, когда интернет отключен, если интернет работает нормально.

Process: com.oktested, PID: 8028
        java.lang.IllegalStateException: ScrollView can host only one direct child
            at androidx.core.widget.NestedScrollView.addView(NestedScrollView.java:444)
            at com.google.android.material.snackbar.BaseTransientBottomBar.showView(BaseTransientBottomBar.java:511)
            at com.google.android.material.snackbar.BaseTransientBottomBar$1.handleMessage(BaseTransientBottomBar.java:191)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:6662)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

XML-код:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/color_black">

        <androidx.core.widget.NestedScrollView
            android:id="@+id/nsvFaces"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

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

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:layout_marginTop="@dimen/_70sdp"
                    android:fontFamily="@font/roboto_regular"
                    android:text="@string/browsebyfaces"
                    android:textColor="@color/colorAccent"
                    android:textSize="@dimen/_24sdp"
                    android:layout_marginRight="@dimen/_10sdp"
                    android:textStyle="bold" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rvFaces"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:layout_marginTop="@dimen/_5sdp"
                    android:layout_marginRight="@dimen/_10sdp"
                    android:layout_marginBottom="@dimen/_10sdp"
                    android:nestedScrollingEnabled="false" />

            </LinearLayout>

        </androidx.core.widget.NestedScrollView>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/_70sdp"
                android:alpha="1"
                android:background="@drawable/bg_gradient_home" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/btnBack"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:padding="@dimen/_10sdp"
                    android:src="@drawable/ic_vector_arrow" />

                <RelativeLayout
                    android:id="@+id/sideMenu"
                    android:layout_width="@dimen/_50sdp"
                    android:layout_height="@dimen/_50sdp"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:padding="@dimen/_12sdp">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:src="@drawable/ic_menu_sky" />

                </RelativeLayout>

            </RelativeLayout>

        </RelativeLayout>

    </RelativeLayout>

У меня также есть поиск по дополнительному результату, но я не могу найти правильное решение, и я уже пробовал каждое решение из приведенной ниже ссылки, но в моем случае это не работает.

ScrollView может содержать только одного прямого дочернего элемента с относительной задержкой
В представлении прокрутки может быть только один прямой дочерний элемент
В представлении прокрутки может быть только один дочерний XML-файл Android
java.lang.IllegalStateException: ScrollView можетхозяин только один прямой ребенок

Если я ошибаюсь, пожалуйста, предложите мне и, пожалуйста, помогите мне.

1 Ответ

0 голосов
/ 14 октября 2019

at com.google.android.material.snackbar.BaseTransientBottomBar.showView(BaseTransientBottomBar.java:511)

Ваша трассировка стека говорит мне, что вы пытаетесь добавить Snackbar в ScrollView.

Snackbar пытается найти родительское представление, гдеон может добавить свою точку зрения. Вы, вероятно, вызвали функцию Snackbar.make() со своим ScrollView, поэтому он пытается добавить туда Snackbar. Если вы передадите RelativeLayout в качестве родительского для функции make, она, как мы надеемся, будет работать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...