NestedScrolling不适用于gridView

问题描述 投票:1回答:1

我在下面尝试将nestedsroll视图用作屏幕滚动时将代码发布在下面,而当我在nestedscrollview中添加“ android:nestedScrollingEnabled =“ true”“时,应用崩溃了,我不知道为什么会这样在嵌套滚动视图中使用网格视图可以有人帮助我,这将很有用,谢谢

<androidx.core.widget.NestedScrollView
    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">
         <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="match_parent">
            <ImageView
                android:id="@+id/wheel"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="right"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="100dp"
                android:src="@drawable/mywheel" />

            <GridView
                android:id="@+id/grid"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/wheel"
                android:layout_marginTop="10dp"
                android:numColumns="5"
                android:layout_marginStart="90dp"
                android:layout_marginEnd="90dp"
                />
            <LinearLayout
                android:layout_width="match_parent"
                android:id="@+id/seat_info"
                android:layout_below="@+id/grid"
                android:layout_height="40dp"
                android:orientation="horizontal"
                android:layout_marginTop="10dp"
                android:layout_marginStart="10dp"
                android:weightSum="3"
                android:layout_marginEnd="10dp"
                >


                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    android:weightSum="2"
                    android:orientation="horizontal"
                    >

                    <ImageView
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_weight=".5"
                        android:src="@drawable/seat_open"
                        />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="30dp"
                        android:layout_weight="1.5"
                        android:gravity="center_vertical"
                        android:text="Available"
                        android:paddingStart="5dp"
                        />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    android:weightSum="3"
                    android:orientation="horizontal"
                    >

                    <ImageView
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_weight=".5"
                        android:src="@drawable/seat_booked"
                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="30dp"
                        android:layout_weight="2.5"
                        android:gravity="center_vertical"
                        android:paddingStart="5dp"
                        android:text="Unavailable"/>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    android:weightSum="2"
                    android:orientation="horizontal"
                    >

                    <ImageView
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_weight=".5"
                        android:src="@drawable/seat_selected"
                        />
                    <TextView
                        android:layout_width="wrap_content"

                        android:layout_height="30dp"
                        android:layout_weight="1.5"
                        android:paddingStart="5dp"
                        android:gravity="center_vertical"
                        android:text="Selected"/>

                </LinearLayout>




            </LinearLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/seat_info"
                android:paddingBottom="10dp">
                <Button
                    android:id="@+id/bt_booking_details"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@drawable/circular_button"
                    android:fontFamily="@font/montserrat_regular"
                    android:text="Enter Booking Details"
                    android:layout_marginBottom="10dp"
                    android:layout_alignParentBottom="true"
                    android:textColor="@android:color/white"
                    android:layout_marginStart="10dp"
                    android:layout_marginEnd="10dp"
                    android:textSize="17dp"
                    android:textStyle="bold" />
            </RelativeLayout>


        </LinearLayout>

    </LinearLayout>

</androidx.core.widget.NestedScrollView>
android gridview android-nestedscrollview
1个回答
0
投票

GridView已经内置了滚动功能,因此它与NestedScrollView冲突。您应该将RecyclerView与GridLayoutManager和appbar_scrolling_view_behavior布局行为一起使用,以代替NestedScrollView。

© www.soinside.com 2019 - 2024. All rights reserved.