1

I found the solution in SOF for using gridview with expanded height inside scrollview from this link. But I have a problem when the gridview items are dynamic.My problem is,

When the items are less, it works fine. If the number of items increases then the Gridview last row or some rows are not visible. And also I am getting some empty space above the first row.

This is my gridview,

 <com.example.xyz.myapp.ExpandableHeightGridView
        android:id="@+id/favor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:clipChildren="false"
        android:fitsSystemWindows="true"
        />

Expandable height gridview code is code is,

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (isExpanded()) {
        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);
    }
}

Can Anyone help me. Thanks in advance.

Jyoti JK
  • 2,141
  • 1
  • 17
  • 40
  • can you scroll the grid view? – sasikumar Feb 05 '18 at 05:08
  • I dont want to scroll it, and I have done `gridView.setEnabled(false);` . – Jyoti JK Feb 05 '18 at 05:09
  • In that case you have to set resize of view based on multiple device.use dimensions values for different screen size. – sasikumar Feb 05 '18 at 05:11
  • I couldn't understand. I just need a non-scrollable gridview to display inside scrollview. Could you please explain – Jyoti JK Feb 05 '18 at 05:13
  • refer https://stackoverflow.com/questions/32860815/how-to-define-dimens-xml-for-every-different-screen-size-in-android. you should set the size of gridview or viewholder element based on various device – sasikumar Feb 05 '18 at 05:16
  • @sasikumar but why should I use it? I haven't defined any dimen values for gridview. I just used `wrap_content` – Jyoti JK Feb 05 '18 at 05:20

0 Answers0