无法删除 CardView 项目之间的额外空间 - Scrollable RecyclerView [英] Unable to remove extra space between CardView items - Scrollable RecyclerView
本文介绍了无法删除 CardView 项目之间的额外空间 - Scrollable RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
各位,
在我的回收站视图中尝试删除 cardview 项目之间的额外空间时,我没有选择,下面是当前输出.请提出建议.
I am out of options while attempting to removing extra space between cardview items in my recyclerview below is the current output. Please suggest.
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#303030"
android:id="@+id/cv"
android:layout_marginTop="2dip"
android:layout_marginBottom="2dip"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="5dp"
android:foreground="?android:attr/selectableItemBackground"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="5dp"
android:longClickable="true"
android:background="#303030">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/person_photo"
android:background="@drawable/vector_red"
android:layout_alignBottom="@+id/txtSub" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/txtMain"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo"
android:elevation="4dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/txtSub"
android:layout_below="@+id/txtMain"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo" />
</RelativeLayout>
</android.support.v7.widget.CardView>
我的回收站视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
card_view:cardUseCompatPadding="false"
card_view:cardPreventCornerOverlap="false"
android:background="#0fffffff" />
</RelativeLayout>
推荐答案
我还没有实现 RecyclerView
,但是我在线性布局中复制了两行,减去原始问题中的填充:
I have not implemented a RecyclerView
, however I have replicated two rows in a linear layout, minus the padding from your original question:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="#303030"
android:id="@+id/cv1"
card_view:cardElevation="5dp"
android:foreground="?android:attr/selectableItemBackground"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_margin="4dp"
android:longClickable="true"
android:background="#303030">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/person_photo"
android:background="@drawable/vector_red"
android:layout_alignBottom="@+id/txtSub" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/txtMain"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo"
android:elevation="4dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/txtSub"
android:layout_below="@+id/txtMain"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="#303030"
android:id="@+id/cv1"
card_view:cardElevation="5dp"
android:foreground="?android:attr/selectableItemBackground"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_margin="4dp"
android:longClickable="true"
android:background="#303030">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/person_photo"
android:background="@drawable/vector_red"
android:layout_alignBottom="@+id/txtSub" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/txtMain"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo"
android:elevation="4dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/txtSub"
android:layout_below="@+id/txtMain"
android:layout_toRightOf="@+id/person_photo"
android:layout_toEndOf="@+id/person_photo" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
试试填充,你会得到更好的结果.您也可以尝试为卡片添加背景颜色,然后您可以在您的 RelativeLayout 中去掉布局边距!
Play around with the padding and you will get better results. You can also try adding a background color to your card, then you can get rid of layout margins in your RelativeLayout!
这篇关于无法删除 CardView 项目之间的额外空间 - Scrollable RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文