当前位置: 首页 > news >正文

集团响应式网站建设房子装修网站

集团响应式网站建设,房子装修网站,公司网站开发费用计入什么科目,网站的域名能换吗原文地址#xff1a;https://developer.android.com/training/gestures/viewgroup.html 在ViewGroup中处理触摸事件要格外小心#xff0c;因为在ViewGroup中有很多子View#xff0c;而这些子View对于不同的触摸事件来说是不同的目标。要确保每个View都正确的接收了相应的触…原文地址https://developer.android.com/training/gestures/viewgroup.html 在ViewGroup中处理触摸事件要格外小心因为在ViewGroup中有很多子View而这些子View对于不同的触摸事件来说是不同的目标。要确保每个View都正确的接收了相应的触摸事件。 在ViewGroup中拦截触摸事件 onInterceptTouchEvent()方法会在触摸事件到达ViewGroup的表面时调用这包括内部的子View。如果onInterceptTouchEvent()返回了true那么MotionEvent对象就会被拦截这意味着该次事件不会传给子View而是会传给ViewGroup本身的onTouchEvent()方法。 onInterceptTouchEvent()给了ViewGroup本身一个机会在子View获得任何事件之前一个拦截该事件的机会。如果onInterceptTouchEvent()返回了true那么原先处理该次事件的子View就会收到一个ACTION_CANCEL的事件并且原先事件的剩余事件都会被传到该ViewGroup的onTouchEvent()方法中做常规处理。onInterceptTouchEvent()还可以返回false这样的话该次事件则会通过View树继续向下传递直到到达目标View为止目标View会在自己的onTouchEvent()方法中处理该次事件。 在下面的示例代码中类MyViewGroup继承了ViewGroup并包含了多个View这些View我们在这里称之为子View而MyViewGroup称为父容器View。如果你在水平方向上滑动手指那么子View皆不会收到触摸事件。MyViewGroup会通过滚动它的内部来实现触摸事件的处理。不管如何如果你按下了子View中的按钮或者在垂直方向上滑动那么ViewGroup则不会去拦截这些事件因为子View是该次事件的目标View。在这些情况下onInterceptTouchEvent()应该返回false且MyViewGroup的onTouchEvent()方法也不会被调用。 public class MyViewGroup extends ViewGroup {private int mTouchSlop;...ViewConfiguration vc ViewConfiguration.get(view.getContext());mTouchSlop vc.getScaledTouchSlop();...Overridepublic boolean onInterceptTouchEvent(MotionEvent ev) {/** This method JUST determines whether we want to intercept the motion.* If we return true, onTouchEvent will be called and we do the actual* scrolling there.*/final int action MotionEventCompat.getActionMasked(ev);// Always handle the case of the touch gesture being complete.if (action MotionEvent.ACTION_CANCEL || action MotionEvent.ACTION_UP) {// Release the scroll.mIsScrolling false;return false; // Do not intercept touch event, let the child handle it}switch (action) {case MotionEvent.ACTION_MOVE: {if (mIsScrolling) {// Were currently scrolling, so yes, intercept the// touch event!return true;}// If the user has dragged her finger horizontally more than// the touch slop, start the scroll// left as an exercise for the readerfinal int xDiff calculateDistanceX(ev);// Touch slop should be calculated using ViewConfiguration// constants.if (xDiff mTouchSlop) {// Start scrolling!mIsScrolling true;return true;}break;}...}// In general, we dont want to intercept touch events. They should be// handled by the child view.return false;}Overridepublic boolean onTouchEvent(MotionEvent ev) {// Here we actually handle the touch event (e.g. if the action is ACTION_MOVE,// scroll this container).// This method will only be called if the touch event was intercepted in// onInterceptTouchEvent...} } 这里要注意ViewGroup还提供了requestDisallowInterceptTouchEvent()方法。当子View不希望它的父容器及祖先容器拦截触摸事件时ViewGroup会在 onInterceptTouchEvent()方法中对其进行调用从而判断是否要拦截本次事件。 使用ViewConfiguration常量 在上面的代码中使用了ViewConfiguration来初始化一个名为mTouchSlop的变量。你可以使用ViewConfiguration来访问Android系统所使用的常用距离、速度及时间。 “mTouchSlop”引用了触摸事件在被拦截之前手指移动的以像素为单位的距离。Touch slop经常被用来在用户在执行触摸操作时防止产生意外滚动。 ViewConfiguration的另外两个常用方法是getScaledMinimumFlingVelocity()和getScaledMaximumFlingVelocity()。这两个方法分别返回了用于初始化滚动的最小、最大的速度值。以每秒几像素为单位 ViewConfiguration vc ViewConfiguration.get(view.getContext()); private int mSlop vc.getScaledTouchSlop(); private int mMinFlingVelocity vc.getScaledMinimumFlingVelocity(); private int mMaxFlingVelocity vc.getScaledMaximumFlingVelocity();...case MotionEvent.ACTION_MOVE: {...float deltaX motionEvent.getRawX() - mDownX;if (Math.abs(deltaX) mSlop) {// A swipe occurred, do something}...case MotionEvent.ACTION_UP: {...} if (mMinFlingVelocity velocityX velocityX mMaxFlingVelocity velocityY velocityX) {// The criteria have been satisfied, do something} } 扩展子View的触控区域 Android提供的TouchDelegate使扩展子View的触控区域成为了可能。这对于子View本身特别小而它的触控区域需要很大时很有用。如果需要的话你也可以使用这种方式来缩小子View的触控区域。 在下面的示例中ImageButton作为我们的”delegate view”(这里的意思是需要父容器扩展触控区域的那个View)。下面是示例的布局文件 RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:idid/parent_layoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.MainActivity ImageButton android:idid/buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:backgroundnullandroid:srcdrawable/icon / /RelativeLayout 下面的代码做了以下这些事情 获得父容器View并Post一个Runnale对象到UI线程。这可以确保在调用getHitRect()方法之前父容器已经对子View完成了排布。getHitRect()会返回父容器坐标内当前View的点击矩阵(触控区域)。找到ImageButton然后调用它的getHitRect()方法获得该View的触控边界。扩大ImageButton的触控区域。实例化一个TouchDelegate将要扩展的触控区域矩阵与要扩展触控区域的ImageView作为参数传入。将TouchDelegate设置给父容器View只有这样做我们所触碰到的扩展区域才会被路由到子View上。 在TouchDelegate代理的范围内父容器View将会接收所有的触摸事件。如果触摸事件发生在子View本身的触控区域内那么父容器View会将所有的触摸事件传给子View处理 public class MainActivity extends Activity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// Get the parent viewView parentView findViewById(R.id.parent_layout);parentView.post(new Runnable() {// Post in the parents message queue to make sure the parent// lays out its children before you call getHitRect()Overridepublic void run() {// The bounds for the delegate view (an ImageButton// in this example)Rect delegateArea new Rect();ImageButton myButton (ImageButton) findViewById(R.id.button);myButton.setEnabled(true);myButton.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {Toast.makeText(MainActivity.this,Touch occurred within ImageButton touch region.,Toast.LENGTH_SHORT).show();}});// The hit rectangle for the ImageButtonmyButton.getHitRect(delegateArea);// Extend the touch area of the ImageButton beyond its bounds// on the right and bottom.delegateArea.right 100;delegateArea.bottom 100;// Instantiate a TouchDelegate.// delegateArea is the bounds in local coordinates of// the containing view to be mapped to the delegate view.// myButton is the child view that should receive motion// events.TouchDelegate touchDelegate new TouchDelegate(delegateArea,myButton);// Sets the TouchDelegate on the parent view, such that touches// within the touch delegate bounds are routed to the child.if (View.class.isInstance(myButton.getParent())) {((View) myButton.getParent()).setTouchDelegate(touchDelegate);}}});} }
http://www.yutouwan.com/news/484408/

相关文章:

  • iis搭建网站404哈尔滨网站优化技术
  • 要想用谷歌访问外国网站怎么做做的好点的外贸网站
  • 门户网站建设技术要求项目经理岗位职责
  • 青岛免费模板建站有好的学网站建设的书吗
  • 基础微网站开发代理商wordpress伪静态格式
  • 中小企业网站制作多少钱十堰网站建设公司
  • 织梦网站如何做二级导航免费wordpress 主题下载
  • 聊城做网站的公司价位南宁企业建站系统模板
  • 开发网站申请企业官网网页设计
  • 做设计有哪些接私活的网站公园网站建设方案 ppt
  • 天河电子商务网站建设火车头 wordpress 发布接口
  • 仿淘宝网站网站seo优化心得
  • 科技企业网站设计南宁网站开发培训
  • 服装网站建设优点有哪些兰州哪有建设网站的
  • 如何查询网站备案时间查询衣柜做网站的关键词
  • 济宁网站制作唐人展示型网页设计
  • 陕西住房和建设厅网站wordpress wp-postviews插件
  • 重庆好的网站制作公司宁德seo公司
  • 国外特效网站wordpress的上传大小
  • 医药电子商务网站建设徐州市工程建设交易平台
  • 千博网站管理系统安装怎么样创建一个网站
  • 如何做网站弹窗广告可以访问违规网站的浏览器
  • 网站换服务器怎么做建设工程施工合同 示范文本
  • wordpress菜单项目边距和填充什么是seo优化推广
  • 阿里云网站托管长沙网站开发微联讯点官网
  • .net 网站开发教程成都中小企业网站建设
  • 网站建设 盘网互联如何做音乐网站
  • 百度怎样建立一个网站wordpress启用GZIP压缩
  • 查询网站备案进度免费登记照制作app
  • 高端网站搭建临汾建设局网站