android GridView禁止上下滑动以及禁止滚动条显示的方法。
来源:互联网 发布:基尼系数数据 编辑:程序博客网 时间:2024/04/28 18:56
一、 android处理鼠标滚轮事件,并不是如下的函数:
1) public boolean onKeyDown(int keyCode, KeyEvent event)
2) public boolean dispatchKeyEvent(KeyEvent event)
3) public boolean onTouchEvent(MotionEvent event)
而是如下的函数
publicboolean onGenericMotionEvent(MotionEvent event);
所有View和Activity都可重写该函数,来自己处理滚轮事件。
网上很多人说用重写dispatchTouchEvent和onTouchEvent方法可以实现禁止滚动的功能,我测试了下,都是不行的,只有重写onGenericMotionEvent方法可以。
具体代码如下:
import android.annotation.SuppressLint;import android.content.Context;import android.util.Log;import android.view.MotionEvent;import android.widget.GridView;public class MyGridView extends GridView {private static final String TAG = "FreeRDP.SessionActivity";public MyGridView(Context context) {super(context);// TODO Auto-generated constructor stub}// 通过重新dispatchTouchEvent方法来禁止滑动@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {// TODO Auto-generated method stubLog.v(TAG, "dispatchTouchEvent....4444444444........." + ev.getAction());if (ev.getAction() == MotionEvent.ACTION_MOVE) {return true;// 禁止Gridview进行滑动}return super.dispatchTouchEvent(ev);}@Overridepublic boolean onTouchEvent(MotionEvent event) {// 重写的onTouchEvent回调方法Log.v(TAG, "dispatchTouchEvent...5555........" + event.getAction());switch (event.getAction()) {// 按下case MotionEvent.ACTION_DOWN:return super.onTouchEvent(event);// 滑动case MotionEvent.ACTION_MOVE:break;// 离开case MotionEvent.ACTION_UP:return super.onTouchEvent(event);}// 注意:返回值是falsereturn false;}@SuppressLint({ "NewApi", "NewApi" })@Overridepublic boolean onGenericMotionEvent(MotionEvent event) {// 重写的onTouchEvent回调方法switch (event.getAction()) {// 按下case MotionEvent.ACTION_DOWN:return super.onGenericMotionEvent(event);// 滑动case MotionEvent.ACTION_MOVE:break;// 离开case MotionEvent.ACTION_UP:return super.onGenericMotionEvent(event);}// 注意:返回值是falsereturn false;}}
二、 禁止滚动条显示
有二种方法禁止滚动条显示:
1、xml添加android:scrollbars="none"属性。
2、代码实现:gridView.setVerticalScrollBarEnabled(false);
2 0
- android GridView禁止上下滑动以及禁止滚动条显示的方法。
- GridView禁止上下滚动的方法
- android中禁止GridView上下滑动的方法
- android中禁止GridView上下滑动的方法
- Android之禁止GridView上下滑动
- Android之禁止GridView上下滑动
- Android中禁止Gridview上下滑动
- Android禁止gridview与listview上下滑动
- android中禁止GridView滑动的方法
- 如何禁止Gridview上下滑动?
- 如何禁止Gridview上下滑动
- 【Android】禁止滑动的GridView
- Android 屏蔽/禁止ListView,GridView的滑动/滚动功能
- (转)Android 屏蔽/禁止ListView,GridView的滑动/滚动功能
- Android - 禁止Gridview滚动
- Android - 禁止Gridview滚动
- Android开发笔记----禁止GridView进行上下滑动
- Android 禁止 ListView 上下滑动
- 多层回归模型简介
- Ryu拓扑发现原理分析
- 背景UIButton
- 术与道
- PPPoE拨号流程
- android GridView禁止上下滑动以及禁止滚动条显示的方法。
- linux防火墙状态查看、打开、关闭、永久关闭
- hdu4549 M斐波那契数列(矩阵快速幂)
- Unity3d-AssetBundle基本格式分析
- 城市、远方和故乡
- Java线程:并发协作-生产者消费者模型
- Django中如何使用django-celery完成异步任务
- 读入一个包含标点符号的字符串,将去掉标点符号之后的字符串输出
- 成功的秘诀在于长久的坚持和耐心