如何禁用GridView的滚动

如何禁用GridView的滚动

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

问题描述

我的应用程序有一个GridView。它已经拥有了onItemClickListener和onItemLongClickListener。我想现在禁用GridView中滚动。随着的帮助下,我增加了一个onTouchListener如下图所示:

My application has a GridView. It already has a onItemClickListener and onItemLongClickListener. I would like to disable the scrolling in the GridView now. With the help of http://stackoverflow.com/a/6496632/985025 I have added an onTouchListener as shown below:

        mGridView.setOnItemClickListener(this);
        mGridView.setOnItemLongClickListener(this);
        mGridView.setOnTouchListener(new OnTouchListener(){
            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                if(arg1.getAction() == MotionEvent.ACTION_MOVE)
                    return true;
                else
                    return false;
            }
        });

我的预期的行为是当过我尝试在GridView中滚动,该事件应该被忽略。但是,我甚至在onTouch返回true后得到onItemClick的事件。
有没有一种方法,以避免在onItemClick滚动的情况下,在GridView的?

My expected behavior is that when ever I try to scroll in the GridView, that event should be ignored. But, I get an event in onItemClick even after returning true in onTouch.Is there a way to avoid onItemClick in case of scroll on GridView?

推荐答案

通过使用下面的语句
我们可以控制在GridView中滚动

By using the following statementwe can control the scrolling in GridView

mGridView..setVerticalScrollBarEnabled(false);

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

08-16 04:37