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"

/>

更多相关文章

  1. Android自定义属性,attr format取值类型
  2. Android输入法之如何自定义每个key的属性
  3. Android(安卓)TabHost 选项卡 滑动activity进行切换选项卡
  4. Android(安卓)高仿知乎日报 (上)
  5. Android之Hello WebView
  6. android控件之spinner (下拉列表)
  7. android 设置控件 圆角
  8. android 状态选择器
  9. Android(安卓)3.0动画系统详解

随机推荐

  1. android studio升级时提示 Connection fa
  2. android SDK 环境变量的设置
  3. Android复习(八)
  4. Android自定义Toast,并解决toast不重复显
  5. android中常见的错误及解决办法
  6. xml-----属性收集
  7. Android之WebView 防止调用系统浏览器打
  8. (Android)为什么我们不需要导入android s
  9. Android中获取当前屏幕的尺寸大小
  10. android点滴(26)之让线程拥有自己的消息