2017-02-25 44 views
0

细胞不交错在Android中使用RecyclerView与StaggeredGridLayoutManager在Android的细胞在使用RecyclerView与StaggeredGridLayoutManager


<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/card_view" 
    android:layout_width="300dp" 
    android:layout_height="226dp" 
    card_view:cardUseCompatPadding="true" 
    card_view:cardCornerRadius="8dp" 
    android:layout_marginBottom="16dp"> 

    <RelativeLayout 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center"> 

     <!-- android:src="@drawable/three"--> 
     <TextView 
      android:id="@+id/price" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="13sp" 
      android:text="$100" 
      android:gravity="center" 
      android:layout_below="@+id/country_photo" 
      android:layout_marginTop="2sp" 

      android:background="#ffffff"/> 
     <TextView 
      android:id="@+id/country_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="13sp" 
      android:text="@string/country_name" 
      android:gravity="center" 
      android:layout_marginTop="3sp" 
      android:layout_below="@+id/price" 
      android:background="#ffffff"/> 
     <TextView 
      android:id="@+id/Descripition" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="13sp" 
      android:text="Descripition" 
android:layout_marginBottom="2dp" 
      android:gravity="center" 
      android:layout_below="@+id/country_name" 
      android:layout_marginTop="3sp" 
      android:background="#ffffff"/> 

     <ImageView 
      android:id="@+id/country_photo" 
      android:layout_width="150dp" 
      android:layout_height="140dp" 
      android:contentDescription="@string/action_settings" 
      android:src="@drawable/three" 
      android:scaleType="fitXY" 
      android:gravity="center" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" /> 

    </RelativeLayout> 

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



    <android.support.v7.widget.RecyclerView 
       android:id="@+id/recycler_view" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical" /> 
+0

你可以请更新你的文章,包括你的代码,XML布局和截图?其他我们不知道问题出在哪里。 –

+0

我使用cardview和回收视图与staggred..but细胞就像网格,他们不会改变 –

+0

请提及您设置的代码的一部分布局管理器RecyclerView –

回答

1

你需要设置你的CardViewandroid:layout_heightwrap_content,否则每CardView不交错将有一个固定的高度300dp,这意味着它们都将是相同的高度。

<android.support.v7.widget.CardView 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/card_view" 
android:layout_width="300dp" 
android:layout_height="wrap_content" 
card_view:cardUseCompatPadding="true" 
card_view:cardCornerRadius="8dp" 
android:layout_marginBottom="16dp"> 

<RelativeLayout 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center"> 

    <!-- android:src="@drawable/three"--> 
    <TextView 
     android:id="@+id/price" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="13sp" 
     android:text="$100" 
     android:gravity="center" 
     android:layout_below="@+id/country_photo" 
     android:layout_marginTop="2sp" 

     android:background="#ffffff"/> 
    <TextView 
     android:id="@+id/country_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="13sp" 
     android:text="@string/country_name" 
     android:gravity="center" 
     android:layout_marginTop="3sp" 
     android:layout_below="@+id/price" 
     android:background="#ffffff"/> 
    <TextView 
     android:id="@+id/Descripition" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="13sp" 
     android:text="Descripition" 
     android:layout_marginBottom="2dp" 
     android:gravity="center" 
     android:layout_below="@+id/country_name" 
     android:layout_marginTop="3sp" 
     android:background="#ffffff"/> 

    <ImageView 
     android:id="@+id/country_photo" 
     android:layout_width="150dp" 
     android:layout_height="140dp" 
     android:contentDescription="@string/action_settings" 
     android:src="@drawable/three" 
     android:scaleType="fitXY" 
     android:gravity="center" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

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



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