2017-10-18 58 views
0

你好我在recyclerview裏面的gridviiew有一些問題,網格項目2上面有一些空格。如果我在recyclerview中重新加載內容,則空間會發生變化。在recyclerview裏的gridview中額外的空格

正常recyclerview

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

        android:layout_height="match_parent" 
        /> 

項cardview

<?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:layout_margin="2dp" 

    android:clickable="true" 
    android:clipChildren="true" 


    card_view:cardPreventCornerOverlap="false" 
    card_view:cardUseCompatPadding="false" 
    android:foreground="?attr/selectableItemBackground" 
    android:orientation="vertical"> 

enter image description here

+0

where is xml ???? –

+0

xml @IntelliJAmiya Amiya – Muklas

回答

0

發現怪異溶液通過在再循環器適配器onBindViewHolder添加2虛設內容並將其取出(2項目1和2)解決了我的問題。

if (position == 1 || position == 0) { 
//    holder; 
       LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
         0, 
         0 
       ); 
       int margin = dpToPx(0); 
       params.setMargins(margin, margin, margin, margin); 
       holder.cardview2.setLayoutParams(params); 
       holder.cardview2.setVisibility(View.GONE); 


      } else { 

那麼最新的問題是什麼?