Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法删除CardView项目之间的额外空间-可滚动回收视图_Android_Android Studio_Android Recyclerview_Android Cardview - Fatal编程技术网

Android 无法删除CardView项目之间的额外空间-可滚动回收视图

Android 无法删除CardView项目之间的额外空间-可滚动回收视图,android,android-studio,android-recyclerview,android-cardview,Android,Android Studio,Android Recyclerview,Android Cardview,各位 尝试在我的recyclerview中删除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/r

各位

尝试在我的recyclerview中删除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>

你能试试这个吗

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
...
...
...
</android.support.v7.widget.CardView>


希望这能对您有所帮助。

我没有实现
RecyclerView
,但是我在线性布局中复制了两行,减去您原始问题中的填充:

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


玩填充,你会得到更好的结果。你也可以尝试在你的卡片上添加背景色,然后你就可以在你的相对主义中去掉版面边距了

将您的卡布局更改为

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         android:background="#303030"
         android:id="@+id/cv"
        card_view:cardCornerRadius="2dp"
        card_view:cardElevation="2dp"
        card_view:cardPreventCornerOverlap="false"
        card_view:cardUseCompatPadding="true">

您只需从
卡片布局的xml中删除以下两行即可:

android:layout_marginTop="2dip"
android:layout_marginBottom="2dip"
这样做的目的是设置两个布局之间的分隔,在这种情况下,您有
4dip
(2个在顶部,2个在底部)。您还可以尝试将其降低到
1度
,并验证它给您带来的效果


希望这对您有所帮助:)

在卡片视图中,将整个父布局的宽度更改为包装内容

android:layout_width="match_parent"


欺骗?不幸的是,那个也没有答案。对,但填充物相对来说还行,我得到了一张难看的cardview,。至少需要一个紧凑的视图。你能发布你想要的屏幕截图吗@xtechkid您正在使用很多填充物,只需将其移除即可!card_view:cardUseCompatPadding=“true”在第一个xml文件中设置为“false”让我检查并返回,很高兴帮助mate:)我也这样做了,但它会给我id的错误bocz重复除非你想要固定的卡(本例中为2),否则在你的卡根线性布局上设置android:layout_height=“wrap\u content”
android:layout_width="match_parent"
android:layout_width="wrap_content"