2016-09-17 5 views

答えて

0

GridLayoutManagerでRecyclerViewを使用すると、scrollview内でgridview(Recyclerview with gridLayout)をスクロールできます。

1

グリッドビューに1つのプロパティを追加するだけで、スクロールビューとグリッドビューの両方をスクロールできます。

アンドロイド:

<ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/linearLayoutTimelineButtons"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 


      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <RelativeLayout 
        android:id="@+id/relativeHeader" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 

        <GridView 
         android:id="@+id/gridMatchedUserGallery" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_alignBottom="@+id/imgProfileBackground" 
         android:layout_alignTop="@+id/imgProfileBackground" 
         android:nestedScrollingEnabled="true" 
         android:numColumns="3" /> 
        </RelativeLayout> 
       </RelativeLayout> 
     </RelativeLayout> 
</ScrollView> 
0

をnestedScrollingEnabled = "true" を、私はpackagename.ExpandableHeightGridView

にしてその作業 変更GridViewのを考える
<com.magazine.screens.ExpandableHeightGridView 
    android:id="@+id/gv_issues" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="6dp" 
    android:layout_marginRight="6dp" 
    android:gravity="center" 
    android:stretchMode="columnWidth" 
    android:numColumns="2" 
    android:isScrollContainer="false" 
    android:verticalSpacing="5dp"> 
</com.magazine.screens.ExpandableHeightGridView> 

その後、ExpandableHeightGridViewのための新しいクラスを作成し、ここにクラス

があります
package com.magazine.screens; 

import android.content.Context; 
import android.util.AttributeSet; 
import android.view.ViewGroup; 
import android.widget.GridView; 

/** 
* Created by muhammed.haris on 31-03-2017. 
*/ 

public class ExpandableHeightGridView extends GridView { 
boolean expanded = false; 

public ExpandableHeightGridView(Context context) { 
    super(context); 
} 

public ExpandableHeightGridView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public ExpandableHeightGridView(Context context, AttributeSet attrs, 
           int defStyle) { 
    super(context, attrs, defStyle); 
} 

public boolean isExpanded() { 
    return expanded; 
} 

@Override 
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    // HACK! TAKE THAT ANDROID! 
    if (isExpanded()) { 
     // Calculate entire height by providing a very large height hint. 
     // View.MEASURED_SIZE_MASK represents the largest height possible. 
     int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, 
       MeasureSpec.AT_MOST); 
     super.onMeasure(widthMeasureSpec, expandSpec); 

     ViewGroup.LayoutParams params = getLayoutParams(); 
     params.height = getMeasuredHeight(); 
    } else { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
    } 
} 

public void setExpanded(boolean expanded) { 
    this.expanded = expanded; 
} 
} 

私は願っています

gridView = (ExpandableHeightGridView) view.findViewById(R.id.gv_issues); 
    gridView.setExpanded(true); //its important 

はその間違い

を働くあなたのクラスでこのコードをddを
関連する問題