Skip to content Skip to sidebar Skip to footer

Add A Gridview To A Listview In Android

I'm trying to create a ListView that will consist of two types of elements: Strings and a GridView. I.e. putting both Strings and a GridView inside one single ListView. The layout

Solution 1:

To answer my own question:

Based on this answer I created this class that works very well:

publicclassNonScrollableGridViewextendsGridView {
    publicNonScrollableGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @OverrideprotectedvoidonMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // Do not use the highest two bits of Integer.MAX_VALUE because they are// reserved for the MeasureSpec modeintheightSpec= MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightSpec);
        getLayoutParams().height = getMeasuredHeight();
    }
}

Post a Comment for "Add A Gridview To A Listview In Android"