无法在水平RecycleView中的项目之间添加边距

阿姆鲁莎·萨伊(Amrutha Saj)

我使用horizo​​ntal RecyclerView,我的列表项之间的边距是恒定的,我想增加列表项的差距,我尝试增加,layout_margin但是没有变化。

以下是我的列表项布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:background="@color/colorWhite"
app:cardElevation="2dp"
app:cardCornerRadius="5dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:selectableItemBackground"
    android:orientation="vertical"
    android:padding="0dp">

    <ImageView
        android:id="@+id/itemImage"
        android:layout_width="170dp"
        android:layout_height="170dp"
        android:layout_gravity="center_horizontal"
        android:layout_margin="10dp"
        android:scaleType="fitCenter"
        android:src="@drawable/ic_launcher_background" />


    <TextView
        android:id="@+id/tvTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/itemImage"
        android:gravity="center"
        android:padding="5dp"
        android:text="Sample title"
        android:textColor="@color/colorTextBlack"
        android:textSize="16dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="14dp"
        android:gravity="center"
        android:textSize="12dp"
        android:textColor="#9f9f9f"
        android:text="2 Aug, London" />

</LinearLayout>

</android.support.v7.widget.CardView>

这是我得到的观点,我想增加项目之间的差距 在此处输入图片说明

有人可以帮我解决这个问题吗?

库尔斯

您可以像这样更改XML并尝试,

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp">

      <android.support.v7.widget.CardView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_margin="10dp"
           android:background="@color/colorAccent"
           app:cardCornerRadius="5dp"
           app:cardElevation="2dp"
           app:cardPreventCornerOverlap="false"
           app:cardUseCompatPadding="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:selectableItemBackground"
        android:orientation="vertical"
        android:padding="0dp">

        <ImageView
            android:id="@+id/itemImage"
            android:layout_width="170dp"
            android:layout_height="170dp"
            android:layout_gravity="center_horizontal"
            android:layout_margin="10dp"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher" />


        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/itemImage"
            android:gravity="center"
            android:padding="5dp"
            android:text="Sample title"
            android:textColor="@color/cardview_dark_background"
            android:textSize="16dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="14dp"
            android:gravity="center"
            android:text="2 Aug, London"
            android:textColor="#9f9f9f"
            android:textSize="12dp" />

    </LinearLayout>

    </android.support.v7.widget.CardView>
</LinearLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章