android中禁止GridView上下滑动的方法
2012-09-21 15:23
459 查看
1,定义一个类继承GridView,如下:
public class SourcePanel extends GridView {
public SourcePanel(Context context) {
super(context);
}
public SourcePanel(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SourcePanel(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
注意:构造方法要将GridView中的三种构造全部写上,否则很可能出现解析xml文件异常的错误。
2,在该类中重写dispatchTouchEvent()方法,如下:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
return true; //禁止GridView滑动
}
return super.dispatchTouchEvent(ev);
}
3,在布局文件(xml)中定义该控件时写全包名,如下(属性跟GridView控件属性一样,按需求自加):
<com.kz.steerwheel.view.SourcePanel
android:id="@+id/sourcePanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
public class SourcePanel extends GridView {
public SourcePanel(Context context) {
super(context);
}
public SourcePanel(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SourcePanel(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
注意:构造方法要将GridView中的三种构造全部写上,否则很可能出现解析xml文件异常的错误。
2,在该类中重写dispatchTouchEvent()方法,如下:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
return true; //禁止GridView滑动
}
return super.dispatchTouchEvent(ev);
}
3,在布局文件(xml)中定义该控件时写全包名,如下(属性跟GridView控件属性一样,按需求自加):
<com.kz.steerwheel.view.SourcePanel
android:id="@+id/sourcePanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
相关文章推荐
- Android开发笔记----禁止GridView进行上下滑动
- android GridView 去掉自带点击边框效果和禁止上下滑动
- Android之禁止GridView上下滑动
- Android之禁止GridView上下滑动
- Android GridView去除自带边框点击效果、去除右侧滚动条、禁止上下滑动
- android中禁止GridView滑动的方法
- 【Android】禁止滑动的GridView
- Android Gridview 禁止滚动的二种方法
- gridview禁止上下滑动
- Android笔记-ViewPager禁止滑动的方法
- 如何禁止Gridview上下滑动
- 纯原生打造GridView单行横向滑动(宽度自适应在父布局居中),手机屏幕px和dp的互换方法,附禁止滑动的自定义方法
- android scrollview组件禁止滑动的方法
- Android 屏蔽/禁止ListView,GridView的滑动/滚动功能
- GridView禁止上下滚动的方法
- android 在listview上的 gallery 禁止上下滑动
- 如何禁止Gridview上下滑动?
- Android 禁止 ListView 上下滑动
- Android--判断listview上下滑动的方法
- (转)Android 屏蔽/禁止ListView,GridView的滑动/滚动功能