android - 去除卡片之间的空间
问题描述
我正在使用 RecyclerView 来存储这些卡片,但我想减少卡片之间的空间。添加 cardPreventCornerOverlap="false" 这一行后,它减少了一点,但仍然太多了。有没有办法做到这一点?
卡片布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10sp"
app:cardBackgroundColor="@color/lightest_black"
app:cardElevation="16dp"
app:cardUseCompatPadding="true"
app:cardPreventCornerOverlap="false"
android:foreground="@drawable/ripple">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sick_linear_layout"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sick_topic"
android:text=""
android:textSize="22sp"
android:padding="16dp"
android:fontFamily="@font/productsansbold"
android:textColor="@color/white"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sick_expandable_layout">
<TextView
android:id="@+id/sick_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/productsansregular"
android:padding="16dp"
android:text=""
android:textColor="@color/gray"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
RecyclerView 布局:
<?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"
android:orientation="vertical"
android:background="@color/light_black"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:paddingLeft="8dp"
tools:context=".IfYoureFeelingSick">
<androidx.recyclerview.widget.RecyclerView
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sick_recyclerView"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</LinearLayout>
解决方案
尝试添加android:layout_margin="-10dp"
到您CardView
以控制由创建的不需要的空间CompatPadding
,无需说您可以将 -10 替换为您想要的任何负数:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10sp"
android:layout_margin="-10dp"
.....
>
推荐阅读
- javascript - 每个句子的前四个单词,但必须以单词 X 开头并以单词 Y 结尾
- google-chrome - Chrome 自定义 DoH 服务器
- hazelcast-jet - 榛树喷气机。接收器的“onComplete”事件?
- javascript - 延迟加载的路线不会在路线更改时显示
- android - Can't access volley answer saved
- flutter - Flutter BottomNavigationBar 在顶部发光?
- java - AWS SWF - Workflow passing activity results with signals driving the workflow
- java - Each microservice has to implement authentication and authorization or it's better one centerized to deal with it?
- sql - 使用索引连接临时表
- azure-api-management - 无法使用 Azure API 管理液体模板解析肥皂响应