无法删除CardView项目之间的额外空间 - 滚动RecyclerView [英] Unable to remove extra space between CardView items - Scrollable RecyclerView

查看:274
本文介绍了无法删除CardView项目之间的额外空间 - 滚动RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

我出的选项,同时试图在我的recyclerview删除cardview项目之间的额外空间下面是电流输出。请建议。

在这里输入的形象描述


 < android.support.v7.widget.CardView
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=#303030
    机器人:ID =@ + ID / CV
    机器人:layout_marginTop =2DIP
    机器人:layout_marginBottom =2DIP
    card_view:cardUseCompatPadding =真
    card_view:cardElevation =5DP
    机器人:前景=机器人:ATTR / selectableItemBackground
    >    < RelativeLayout的
        机器人:layout_width =match_parent
        机器人:layout_height =80dp
        机器人:填充=5DP
        机器人:longClickable =真
        机器人:背景=#303030>        < ImageView的
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:ID =@ + ID / person_photo
            机器人:背景=@绘制/ vector_red
            机器人:layout_alignBottom =@ + ID / txtSub/>
        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:textAppearance =机器人:ATTR / textAppearanceLarge
            机器人:文字=大文本
            机器人:ID =@ + ID / txtMain
            机器人:layout_alignParentTop =真
            机器人:layout_toRightOf =@ + ID / person_photo
            机器人:layout_toEndOf =@ + ID / person_photo
            机器人:海拔=4DP
            机器人:TEXTSIZE =20dp/>        <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:textAppearance =机器人:ATTR / textAppearanceSmall
            机器人:文字=小文本
            机器人:ID =@ + ID / txtSub
            机器人:layout_below =@ + ID / txtMain
            机器人:layout_toRightOf =@ + ID / person_photo
            机器人:layout_toEndOf =@ + ID / person_photo/>    < / RelativeLayout的>< /android.support.v7.widget.CardView>

我的回收站视图

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=。HomeFragment>< android.support.v7.widget.RecyclerView
    机器人:ID =@ + ID / RV
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:滚动条=垂直
    card_view:cardUseCompatPadding =假
    card_view:卡preventCornerOverlap =假
    机器人:背景=#0fffffff/> < / RelativeLayout的>


解决方案

我还没有实现一个 RecyclerView ,但是我已经在一个线性布局复制的两排,减从原来的问题填充:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直的android:layout_width =match_parent
    机器人:layout_height =match_parent>
    < android.support.v7.widget.CardView
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
        机器人:背景=#303030
        机器人:ID =@ + ID / CV1
        card_view:cardElevation =5DP
        机器人:前景=机器人:ATTR / selectableItemBackground
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>        < RelativeLayout的
            机器人:layout_width =match_parent
            机器人:layout_height =80dp
            机器人:layout_margin =4DP
            机器人:longClickable =真
            机器人:背景=#303030>            < ImageView的
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:ID =@ + ID / person_photo
                机器人:背景=@绘制/ vector_red
                机器人:layout_alignBottom =@ + ID / txtSub/>
            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:textAppearance =机器人:ATTR / textAppearanceLarge
                机器人:文字=大文本
                机器人:ID =@ + ID / txtMain
                机器人:layout_alignParentTop =真
                机器人:layout_toRightOf =@ + ID / person_photo
                机器人:layout_toEndOf =@ + ID / person_photo
                机器人:海拔=4DP
                机器人:TEXTSIZE =20dp/>            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:textAppearance =机器人:ATTR / textAppearanceSmall
                机器人:文字=小文本
                机器人:ID =@ + ID / txtSub
                机器人:layout_below =@ + ID / txtMain
                机器人:layout_toRightOf =@ + ID / person_photo
                机器人:layout_toEndOf =@ + ID / person_photo/>        < / RelativeLayout的>    < /android.support.v7.widget.CardView>
    < android.support.v7.widget.CardView
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
        机器人:背景=#303030
        机器人:ID =@ + ID / CV1
        card_view:cardElevation =5DP
        机器人:前景=机器人:ATTR / selectableItemBackground
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>        < RelativeLayout的
            机器人:layout_width =match_parent
            机器人:layout_height =80dp
            机器人:layout_margin =4DP
            机器人:longClickable =真
            机器人:背景=#303030>            < ImageView的
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:ID =@ + ID / person_photo
                机器人:背景=@绘制/ vector_red
                机器人:layout_alignBottom =@ + ID / txtSub/>
            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:textAppearance =机器人:ATTR / textAppearanceLarge
                机器人:文字=大文本
                机器人:ID =@ + ID / txtMain
                机器人:layout_alignParentTop =真
                机器人:layout_toRightOf =@ + ID / person_photo
                机器人:layout_toEndOf =@ + ID / person_photo
                机器人:海拔=4DP
                机器人:TEXTSIZE =20dp/>            <的TextView
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:textAppearance =机器人:ATTR / textAppearanceSmall
                机器人:文字=小文本
                机器人:ID =@ + ID / txtSub
                机器人:layout_below =@ + ID / txtMain
                机器人:layout_toRightOf =@ + ID / person_photo
                机器人:layout_toEndOf =@ + ID / person_photo/>        < / RelativeLayout的>    < /android.support.v7.widget.CardView>< / LinearLayout中>

玩的填充,你会得到更好的效果。您也可以尝试添加背景色,以你的卡,那么你可以得到你的RelativeLayout布局摆脱利润率!

Folks,

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>

My Recycler view

 <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>

解决方案

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>

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项目之间的额外空间 - 滚动RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆