如何在 Android 中禁用 GridView 滚动? [英] How to disable GridView scrolling in Android?

查看:26
本文介绍了如何在 Android 中禁用 GridView 滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 GridView 用于游戏板.最近,一些用户遇到了板垂直滚动的问题(在运行 2.2 的三星 Galaxy/Vibrant 手机上)——这个错误在我的 Nexus One 上没有发生.

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.

如何将 GridView 锁定到位?有没有办法禁用滚动?

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

推荐答案

Try to add or override setOnTouchListener for GridView,然后在 onTouch 方法中,您可以使用这样的代码使 gridView 不可滚动

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;
    }

});

科特林

gridView.setOnTouchListener { v, event ->
    event.action == MotionEvent.ACTION_MOVE
}

这篇关于如何在 Android 中禁用 GridView 滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆