转载:http://www.liuzhaocn.com/?p=326
新建myGridView类,重写onTouchEvent方法:
Java语言: myGridView
public class myGridView extends GridView {
public myGridView(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//重写的onTouchEvent回调方法
switch(event.getAction()){
//按下
case MotionEvent.ACTION_DOWN:
System.out.println(“ACTION_DOWN”);
return super.onTouchEvent(event);
//滑动
case MotionEvent.ACTION_MOVE:
System.out.println(“ACTION_MOVE”);
break;
//离开
case MotionEvent.ACTION_UP:
System.out.println(“ACTION_UP”);
return super.onTouchEvent(event);
}
//注意:返回值是false
return false;
}
}
我相信大家一看就会明白的,但是要注意返回值要是false因为只有滑动动作的时候才break出来,然后返回,其他两种操作交给父类来进行正常的处理。这样,直接返回,什么都不会去做,当然也不会滚动了。(估计返回true也可)。
可以在其parent view中重写dispatchTouchEvent(event)方法。
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
if(ev.getAction() == MotionEvent.ACTION_MOVE){
return true;//forbid its child(gridview) to scroll
}
return super.dispatchTouchEvent(ev);
}
分享到:
相关推荐
本文实例讲述了Android TextView实现垂直滚动效果的方法。分享给大家供大家参考,具体如下: 在TextView中,如果文本很长,可能需要实现垂直滚动显示文本的效果。这里需要在XML布局文件中为TextView设置如下几个属性...
在AndroidManifest.xml的activity(需要禁止转向的activity)配置中加入android:screenOrientation=”landscape”属性即可(landscape是横向,portrait是纵向)。例如: <?xml version=1.0 encoding=utf-8?> &...
android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height=...
Android数字自动滚动效果,修复之前报错不能运行的情况
android左右滚动焦点图 android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="230px" android:spacing="10px" />
android:scheme 通过uri跳转到APP应用指定Activity
内部有两个比较有价值的东西,一个是,文字过长时,自动的滚动显示组件;另一个是优雅的滑动组件。类似于gallery的侧滑效果。
android+滚动Edittextandroid+滚动Edittextandroid+滚动Edittextandroid+滚动Edittextandroid+滚动Edittextandroid+滚动Edittextandroid+滚动Edittextandroid+滚动Edittextandroid+滚动Edittextandroid+滚动Edittext
《深入理解Android:卷2》是“深入理解Android”系列的第2本,第1本书上市后获得广大读者高度评价,在Android开发者社群内口口相传。《深入理解Android:卷2》不仅继承了第1本书的优点并改正了其在细微处存在的一些...
android 滚动数字选择器
本文实例讲述了Android基于TextView属性android:ellipsize实现跑马灯效果的方法。分享给大家供大家参考,具体如下: Android系统中TextView实现跑马灯效果,必须具备以下几个条件: 1、android:ellipsize=”marquee...
Android 滚动选择控件
Android:TextView的垂直滚动效果和上下滚动效果,原生动画实现
anylife.scrolltextview.ScrollTextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_...
android横向滚动列表,ListView横向展示
NULL 博文链接:https://gundumw100.iteye.com/blog/1060878
android 循环banner自动滚动,主页滚动图片
android 字母滚动条
网上有很多解决 android listview 水平和垂直滚动的代码,我没有按照他们说的做(以前没搜到 O(∩_∩)O~) 我采用的是添加HorizontalScrollViewJava代码 代码如下: < ScrollView android:id=”@+id/ScrollView01″ ...
最简洁易懂的仿淘宝android客户端图片滚动效果