Skip to content Skip to sidebar Skip to footer

Locking Scroll Of Gridview

I have one gridview in my UI but it scrolls vertically I have set all the scrollbar properties as false but its still scrolling. Any idea why this is so? please help. This is my la

Solution 1:

Try to add or override setOnTouchListener for GridView, then in onTouch method you can use code like this to make gridview not scrolling :

gridview.setOnTouchListener(newOnTouchListener(){

    @OverridepublicbooleanonTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_MOVE){
            returntrue;
        }
        returnfalse;
    }

});

Solution 2:

Use this custom gridview. It automatically sets the height and does not scroll:

publicclassMyGridViewextendsGridView {
    publicMyGridView(Context context) {
        super(context);
    }

    publicMyGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

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

    @OverrideprotectedvoidonMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int heightSpec;

        if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
            // The great Android "hackatlon", the love, the magic.// The two leftmost bits in the height measure spec have// a special meaning, hence we can't use them to describe height.
            heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        } else {
            heightSpec = heightMeasureSpec;
        }

        super.onMeasure(widthMeasureSpec, heightSpec);
    }
}

Solution 3:

GridView is designed to scroll vertically, and I am not aware that you can stop it from scrolling. If you do not want scrolling, do not use a GridView.

Solution 4:

publicclassmyGridViewextendsGridView {

    publicmyGridView(Context context) {
        super(context);
    }

    @OverridepublicbooleanonTouchEvent(MotionEvent event) {

    switch(event.getAction()){

    caseMotionEvent.ACTION_DOWN:
    returnsuper.onTouchEvent(event);

    caseMotionEvent.ACTION_MOVE:
    //Do nothing here!!!break;

    caseMotionEvent.ACTION_UP:
    returnsuper.onTouchEvent(event);
    }

    //false return returnfalse;
    }
}

Post a Comment for "Locking Scroll Of Gridview"