簡體   English   中英

如果互聯網關閉,則出現錯誤 java.lang.IllegalStateException: ScrollView can host only one direct child

[英]If internet is off getting error java.lang.IllegalStateException: ScrollView can host only one direct child

我正在使用具有單一布局的 NestedScrollView,但是如果 Internet 上的 Internet 工作正常,它們會在 Internet 關閉時給我如下所示的錯誤。

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 只能使用 relativelayout 托管一個直接子級
Scrollview 只能托管一個直接子級
一個滾動視圖只能有一個子 Android XML 文件
java.lang.IllegalStateException: ScrollView 只能承載一個直接子級

如果我錯了,請建議我並幫助我。

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

您的堆棧跟蹤告訴我您嘗試將 Snackbar 添加到 ScrollView。

Snackbar 試圖找到可以添加其視圖的父視圖。 您可能使用 ScrollView 調用了Snackbar.make() function,因此它會嘗試在此處添加 Snackbar。 如果您將 RelativeLayout 作為父級傳遞給make function 它有望工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM