Cardview 与使用回收器视图和线性布局的父视图不匹配

问题描述

我正在为我的搜索项使用回收器视图,但现在卡片视图看起来比我调试或运行时在设计编辑器中显示的要小。这是我的 cardview xml 文件,当应用程序运行时,它将包含在回收器视图中。

<?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout
        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="wrap_content">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <GridLayout
                android:layout_gravity="center"
                android:id="@+id/my_gridLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:alignmentMode="alignMargins"
                android:columnCount="1"
                android:columnorderPreserved="false"
                android:orientation="horizontal">
    
                <androidx.cardview.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_columnWeight="1"
                    android:layout_rowWeight="1"
                    app:cardElevation="4dp"
                    app:cardCornerRadius="16dp"
                    android:layout_margin="2dp">
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center"
                        android:padding="15dp"
                        android:orientation="vertical">
    
                        <ImageView
                            android:layout_gravity="left"
                            android:background="@drawable/ic_launcher_background"
                            android:id="@+id/productimage"
                            android:layout_width="60dp"
                            android:layout_height="60dp"
                            />
    
                        <TextView
                            android:text="productName goes here"
                            android:id="@+id/productCat"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textSize="10sp"
                            android:layout_marginTop="12dp"/>
    
                    </LinearLayout>
    
                </androidx.cardview.widget.CardView>
    
    
            </GridLayout>
    
    
        </LinearLayout>
    
    </LinearLayout>

下面是 Activity 主 xml 文件,它将在运行时包含 cardview。 I have attached a screenshots of how it appears at runtime here

<?xml version="1.0" encoding="utf-8"?>

<androidx.appcompat.widget.LinearLayoutCompat
    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:background="@color/white"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="125dp"
        app:queryBackground="@drawable/bg_light_sky_blue"
        app:submitBackground="@drawable/bg_light_sky_blue"
        android:background="@drawable/bg_light_sky_blue"
        android:orientation="vertical">

        <ImageView
            android:layout_width="32dp"
            android:layout_height="27dp"
            android:layout_marginLeft="10dp"
            android:onClick="OptionsClick"
            android:src="@drawable/ic_baseline_menu_24">

        </ImageView>

        <ImageView
            android:onClick="CartClick"
            android:layout_width="27dp"
            android:layout_height="27dp"
            android:layout_marginRight="10dp"
            android:src="@drawable/ic_baseline_shopping_cart_24"
            android:layout_gravity="right"
            android:layout_marginTop="-29dp">

        </ImageView>

        <LinearLayout
            android:layout_marginTop="22dp"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <SearchView
                android:iconifiedByDefault="false"
                android:queryHint="@string/search_hint"
                android:id="@+id/mSearch"
                android:layout_height="38dp"
                android:layout_width="349dp"
                android:background="@drawable/bg_white_rounded">
                <requestFocus/>
            </SearchView>

        </LinearLayout>
    </LinearLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:background="@color/white"
        android:id="@+id/myRecycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical">


    </androidx.recyclerview.widget.RecyclerView>

</androidx.appcompat.widget.LinearLayoutCompat>

解决方法

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

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

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

相关问答

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