问题
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 https://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;
}
});
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?
回答1:
Use a TableLayout. Achieves exactly what you want. A GridView is a super overkill in your use case with all its recycling.
回答2:
Folks here have engulfed the GridView with a ScrollView and that did the trick, I hope it helps anyone who is stuck with this problem.
来源:https://stackoverflow.com/questions/8908228/how-to-disable-scrolling-in-gridview