I found a way to provide a GridView with a fixed size inside a ScrollView and enable scrolling . This allows you to see the entire ScrollView without having to scroll through all the GridView elements, and for me it makes more sense to use ExpandableHeightGridView.
To do this, you will need to implement a new class that extends the GridView and overrides onTouchEvent () to call requestDisallowInterceptTouchEvent (true). Thus, the parent view will leave the mesh interception touch events.
GridViewScrollable.java:
package com.example; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.GridView; public class GridViewScrollable extends GridView { public GridViewAdjuntos(Context context) { super(context); } public GridViewAdjuntos(Context context, AttributeSet attrs) { super(context, attrs); } public GridViewAdjuntos(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onTouchEvent(MotionEvent ev){
Add it to your layout with the characteristics and fields you want inside the ScrollView:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:isScrollContainer="true" > <com.example.GridViewScrollable android:id="@+id/myGVS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:numColumns="auto_fit" android:stretchMode="columnWidth" /> </ScrollView>
And just get it in your activity:
GridViewScrollable myGridView = (GridViewScrollable) findViewById(R.id.myGVS);
I hope this helps =)
Lionel T. Nov 11 '14 at 15:41 2014-11-11 15:41
source share