android - 当我向下滚动时,CardView 布局之间的间距很大
问题描述
我正在制作一种库存搜索应用程序。我有一个问题,我尝试在突然出现的卡片视图之间上下滚动一个巨大的空间。当我进行搜索时,布局会重置为正常,但是当我进行滚动时,问题就出现了。下面是我的 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>
解决方案
它发生是因为你match_parent
在你的标签上<LinearLayout/>
变成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">
推荐阅读
- javascript - Expo错误-崩溃后,Android后退按钮导致独立应用程序进入后台
- excel - 为什么空的excel文件是5.5mb大?
- python - python初学者语法语句if-elif
- c# - 错误 VSSDK1001:找不到 Microsoft.VisualStudio.CommandTable.VSCTCompiler 类型
- c++ - 我应该在用户定义的文字中抛出什么异常?
- nativescript - RadListView 是否还存在(Nativescript pro-ui)
- jenkins - 如何使用 groovy 在 Jenkins 中发送最重要的通知?
- postgresql - 连接到 Postgres 数据库的 Docker 容器
- reactjs - React Native - 如何设置环境变量 REACT_DEBUGGER?
- c# - ASP.NET MVC 在将一个表复制到另一个表后删除该行