2017-02-23 63 views
0

我正在制作新闻应用程序,或者没有。我有与CardViews RecyclerView。当我启动它时,每张卡片都会粘在其他卡片上,因此看起来像一张大卡片。我怎样才能分开它?RecyclerView物品互相粘在一起

卡:

<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:fresco="http://schemas.android.com/apk/res-auto" 
android:id="@+id/cv" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:paddingTop="10dp" 
android:paddingBottom="10dp"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="16dp"> 

    <com.facebook.drawee.view.SimpleDraweeView 
     fresco:placeholderImage="@drawable/my_drawable" 
     android:id="@+id/markPhoto" 
     android:layout_width="130dp" 
     android:layout_height="130dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginRight="16dp" /> 

    <TextView 
     android:id="@+id/x" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/markPhoto" /> 

    <TextView 
     android:id="@+id/y" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/x" 
     android:layout_toRightOf="@+id/markPhoto" /> 

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

RecyclerView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:padding="16dp"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


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

屏幕看起来是这样 enter image description here

回答

1

填充在元素内部添加空间,并且边距在外部添加空间。我会尝试将android:layout_marginBottom="4dp"添加到您的CardView。

<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:fresco="http://schemas.android.com/apk/res-auto" 
android:id="@+id/cv" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:paddingTop="10dp" 
android:paddingBottom="10dp" 
android:layout_marginBottom="4dp" > 
+0

ty,它有帮助。为RelativeLayout添加保证金没有解决问题,但CardView halped。非常感谢 –

+0

很高兴我能帮上忙! – drawinfinity

1

添加保证金的RelativeLayout

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:fresco="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/cv" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="10dp" 
    android:paddingBottom="10dp"> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="16dp" 
     android:layout_margin="10dp"> 

     <com.facebook.drawee.view.SimpleDraweeView 
      fresco:placeholderImage="@drawable/my_drawable" 
      android:id="@+id/markPhoto" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginRight="16dp" /> 
      . 
      . 
      . 
    </RelativeLayout> 
    </android.support.v7.widget.CardView> 
0

为了您的信息

是。您可以使用填充nice.But它是真棒,如果您自定义 cardView

添加

card_view:cardCornerRadius="4dp" //for corner radius 
android:layout_margin="5dp"   //for separating views 

,你可以添加边框。试试这个

drawable文件夹中创建bg.xml并粘贴这段代码。

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <solid android:color="#F00" /> 
    <size android:width="10dp"/> 

    <corners android:topLeftRadius="5dp" android:bottomLeftRadius="5dp" 
     android:topRightRadius="0.1dp" android:bottomRightRadius="0.1dp"/> 
</shape> 

添加android:background="@drawable/bg"到您的卡片视图

参考this

enter image description here