android中禁止GridView上下滑动的方法
1,定义一个类继承GridView,如下:
publicclassSourcePanelextendsGridView{
publicSourcePanel(Contextcontext){
super(context);
}
publicSourcePanel(Contextcontext,AttributeSetattrs){
super(context,attrs);
}
publicSourcePanel(Contextcontext,AttributeSetattrs,int defStyle){
super(context,attrs,defStyle);
}
}
注意:构造方法要将GridView中的三种构造全部写上,否则很可能出现解析xml文件异常的错误。
2,在该类中重写dispatchTouchEvent()方法,如下:
@Override
publicbooleandispatchTouchEvent(MotionEventev){
if(ev.getAction()==MotionEvent.ACTION_MOVE){
returntrue;//禁止GridView滑动
}
returnsuper.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自定义属性,attr format取值类型
- Android输入法之如何自定义每个key的属性
- Android(安卓)TabHost 选项卡 滑动activity进行切换选项卡
- Android(安卓)高仿知乎日报 (上)
- Android之Hello WebView
- android控件之spinner (下拉列表)
- android 设置控件 圆角
- android 状态选择器
- Android(安卓)3.0动画系统详解