Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable GridView scrolling in Android?

I'm using a GridView for a game board. Recently some users have had problems with the board scrolling vertically (on Samsung Galaxy / Vibrant phones running 2.2) -- This bug does not occur on my Nexus One.

One user produced some screenshots of the problem.

How could I lock the GridView in place? Is there a way to disable scrolling?

like image 660
pjama Avatar asked Jan 31 '11 15:01

pjama


People also ask

Is GridView scrollable Android?

Grid view requires an adapter to fetch data from the resources. This view can be scrolled both horizontally and vertically. The scrolling ability of the GridView by default is set to enabled.

How do I turn off scroll in grid view flutter?

You can provide physics: NeverScrollableScrollPhysics() on GridView to disable scroll effect. If you want scrollable as secondary widget use primary: false, To have Full Page scrollable, you can use body:SingleChildScrollView(..) or better using body:CustomScrollView(..)

Is Gridlayout scrollable?

When you add item to grid layout, depend on Column count Grid layout will start to scroll.


2 Answers

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

Java

gridView.setOnTouchListener(new OnTouchListener() {      @Override     public boolean onTouch(View v, MotionEvent event) {         return event.getAction() == MotionEvent.ACTION_MOVE;     }  }); 

Kotlin

gridView.setOnTouchListener { v, event ->     event.action == MotionEvent.ACTION_MOVE } 
like image 129
Fadhlan Avatar answered Oct 02 '22 18:10

Fadhlan


You can try setEnabled(false), although it might have other side effects. GridView is really not meant to be used the way you are using it. You should create your own custom view or layout. You could also use a TableLayout.

like image 30
Romain Guy Avatar answered Oct 02 '22 17:10

Romain Guy