开发者

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 di开发者_如何学Csable scrolling?


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
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜