android - CardView 之间的差距过大
问题描述
我使用 CardView。但是卡之间的差距很大。间隙等于一屏。我做错了什么?在滚动卡片视图之前看起来不错。滚动后卡片之间的间隙会增加。
content_main.xml
<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"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/program_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout>
program_item.xml
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:contentPadding="10dp"
android:layout_marginBottom="5dp"
card_view:cardUseCompatPadding="false"
card_view:cardPreventCornerOverlap="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/programName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</android.support.v7.widget.CardView>
解决方案
使您的线性布局 wrap_content 在卡片视图中。它占据了所有的高度
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:contentPadding="10dp"
android:layout_marginBottom="5dp"
card_view:cardUseCompatPadding="false"
card_view:cardPreventCornerOverlap="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/programName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
推荐阅读
- mysql - 解决关于 ONLY_FULL_GROUP_BY SQL 模式的查询失败
- r - 我需要通过将标题(第一行)复制到列变量并将第二行作为 R 中的标题来读取文件夹中的一组 .CSV 文件
- java - 通过组合两个查询结果进行分页
- c# - Xamarin Forms 在导航栏下方创建一个标签
- python - 1)如何在 pandas Bokeh 中切换科学记数法(使用 plot_bokeh 函数)和 2)如何将颜色居中为 0(所以白色为 0)
- sql - Postgres - 在转义双引号内转义双引号
- node.js - 我的 REST API 与 POSTMAN 一起正常运行,但在从前端服务器/客户端服务器调用时无法处理请求
- javascript - 如何将我的输入值存储在变量中并在本地存储数据
- python - python中的映射、求和和条件
- reactjs - React Modal 仅在我单击背景或关闭图标时关闭?