网格视图子项在一行中变得可滚动,如何停止子项的滚动呢?

问题描述

我在嵌套滚动视图中有网格视图,我希望gridview根据内容具有其高度,但是gridview子级变为可滚动的,并且其高度等于1行。 我如何停止滚动子网格并根据内容包装其高度 我需要gridview具有根据可用内容的高度,并且不变得具有等于1行的高度的可滚动 这是xml代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <include layout="@layout/toolbar" />

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.nestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/appbarLayout">

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

            <androidx.cardview.widget.CardView
                android:id="@+id/category_card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:elevation="@dimen/cardview_default_elevation"
                app:cardCornerRadius="10dp">

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

                    <TextView
                        android:id="@+id/header_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp"
                        android:paddingStart="5dp"
                        android:text="Categories"
                        android:textSize="30sp"
                        android:textStyle="bold" />


                    <GridView
                        android:id="@+id/recyclerViewCategory"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_below="@id/header_text"
                        android:nestedScrollingEnabled="false"

                        android:numColumns="4"
                        tools:listitem="@layout/item_category" />
                </LinearLayout>
            </androidx.cardview.widget.CardView>


            <com.skydoves.elasticviews.ElasticCardView
                android:id="@+id/favourite_card_home"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/category_card"
                android:layout_margin="5dp"
                android:elevation="@dimen/cardview_default_elevation"
                app:cardBackgroundColor="@color/colorPrimary"
                app:cardCornerRadius="10dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:paddingHorizontal="10dp"
                    android:paddingVertical="20dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="50dp"
                        android:gravity="end"
                        android:text="Favourite quotes"
                        android:textColor="@android:color/white"
                        android:textSize="30sp"
                        android:textStyle="italic|bold"

                        />

                    <ImageView
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:layout_gravity="start"
                        android:layout_marginStart="10dp"
                        android:padding="10dp"
                        android:src="@drawable/ic_favorite_checked" />

                </LinearLayout>
            </com.skydoves.elasticviews.ElasticCardView>


            <com.skydoves.elasticviews.ElasticCardView
                android:id="@+id/quotes_of_the_day_card_home"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/favourite_card_home"
                android:layout_margin="5dp"
                android:elevation="@dimen/cardview_default_elevation"
                app:cardBackgroundColor="@color/colorDetailRed"
                app:cardCornerRadius="10dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:paddingHorizontal="10dp"
                    android:paddingVertical="20dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="50dp"
                        android:gravity="end"
                        android:text="Quotes of the day"
                        android:textColor="@android:color/white"
                        android:textSize="30sp"
                        android:textStyle="italic|bold"

                        />


                </LinearLayout>
            </com.skydoves.elasticviews.ElasticCardView>

            <View
                android:id="@+id/view"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_below="@id/quotes_of_the_day_card_home"
                android:layout_marginHorizontal="5dp"
                android:layout_marginVertical="8dp"
                android:background="@color/colorPrimary" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerViewDetailCategory"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/view"
                android:layout_margin="5dp"
                android:nestedScrollingEnabled="false" />

        </RelativeLayout>
    </androidx.core.widget.nestedScrollView>
</RelativeLayout>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...