当前位置: 首页 > 知识库问答 >
问题:

当我向下滚动时,CardView布局在它们之间有很大的间距

谢夜洛
2023-03-14

我在做一个库存搜索应用程序。我有一个问题,我试图上下滚动一个巨大的空间之间的卡片视图,突然出现。当我进行搜索时,布局重置为正常,但当我进行滚动时,问题就出现了。下面是我的list_layout.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="6dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="1dp"
        app:cardCornerRadius="17dp"
        android:background="#EFEFEF"
        app:cardElevation="1dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TableLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:stretchColumns="0,1"
                android:layout_marginTop="20dp">

                <TableRow
                    android:layout_width="match_parent"
                    android:paddingBottom="8dp"
                    android:layout_height="match_parent">

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

                        <ImageView
                            android:layout_width="170dp"
                            android:layout_height="150dp"
                            android:layout_column="0"/>
                    </LinearLayout>

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

                        <TextView
                            android:id="@+id/textViewName"
                            android:textAppearance="@style/TextAppearance.AppCompat.Light.SearchResult.Title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:textColor="#000000"
                            android:textSize="15dp"
                            android:textStyle="bold">

                        </TextView>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="10dp"
                            android:text="Over 700 items in store!"
                            android:textColor="#000000"
                            android:textSize="12dp"
                            android:textStyle="bold">

                        </TextView>

                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:background="#FF0000">

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="ON SALE !"
                                android:textColor="#fff"
                                android:textStyle="bold">

                            </TextView>

                        </LinearLayout>

                        <Button
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginTop="19dp"
                            android:background="@drawable/checkout_button"
                            android:onClick="groceries_click"
                            android:text="shop now!"
                            android:textAllCaps="false"
                            android:textSize="12dp">
                        </Button>
                    </LinearLayout>
                </TableRow>
            </TableLayout>
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>

视图的图像在我向下滚动之前得到。这是我在卷轴上得到的行为

共有1个答案

公良育
2023-03-14

这是因为您在标记 上设置了match_parent

更改为wrap_content

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" //Change into wrap_content
    android:padding="6dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">
 类似资料:
  • 问题内容: 滚动搜索可以设置的最大滚动时间是多少? 文档:https : //www.elastic.co/guide/zh- CN/elasticsearch/client/javascript-api/current/api-reference.html#api- scroll 问题答案: 没有最大滚动时间的所有值。 扫描和滚动旨在以块的形式扫描大量记录。每个块的最大值必须通过增量增加来获得,

  • 我正在用GUI制作一个基于文本的游戏。我正在使用Javafx,我正在尝试使用网格窗格排列元素。我正在尝试这样做:举例。 这是我的代码和目前的样子 就像这个例子2所示,我试图将魔法力移到健康标签下,并缩小列表框。网格是正确的方法还是有更好的方法? 谢啦

  • 问题内容: 我有2个要用于修改相同数据的不同布局文件,我将切换到“编辑视图”的布局,该布局允许用户修改图形数据,然后允许他们切换回“详细视图” ”显示详细的图表(使用androidplot库)。 我的问题是,当切换回我的“编辑视图”时,我的图形线不见了,只绘制了轴(因此布局切换,而我的图形视图被调用了onDraw())。一切都存储在同一个活动中,所以我不明白为什么这不起作用? 这些行存储在Grap

  • 我已经搜索了很多关于如何使用SlidengTablayout在片段之间进行通信的内容,但还没有找到一个好的答案。我知道使用ActionBar,但我想要的是androidLollipop使用SlidingTabLayout的新方式。我试过了-

  • 问题内容: 我正在尝试在具有的容器内添加一些元素。 问题是,当我缩小屏幕时,它会在我尚未设置的元素之间形成间隙(或者至少我不这么认为)。 我创建了一个[SFiddle来代表我的问题。 如您所见,当您缩小屏幕时,第一和第二个div之间会有一个蓝色空间。 我该如何解决? 提前致谢! 问题答案: 创建Flex容器时,初始设置为 。 这导致多行柔性物品沿容器的横轴均匀地分布。有点像沿主轴设置:伸缩项均匀地

  • 问题内容: 作为对象,我将重现两个布局之间的淡入淡出效果。现在我有这种情况: 在它们之间切换 我想在这种转换之间添加淡入淡出效果,该怎么办? 问题答案: 使用R.anim.fade_out和.R.anim.fade_in,您可以创建执行此操作的动画。我本人对此并不了解,但这里有一个有关android中动画的教程:动画教程 PS本教程不是我的,因此信誉不归我所有。 编辑: 淡出动画 我猜想您可以尝试