1:view的位置讲解:

      left  right  top bottom  注意他们都是相对于view的父容器  (系统正方向 x轴向右  y

      轴向下)

      图解见下:

      view讲解

      android3.0之后 又额外添加几个参数  x  y  TranslationX   TranslationY  

      x 和y是view的左上角的坐标值, 注意随着TranslationX   TranslationY  的

      变化,x 和y 会随着变化

      x=left+translationX;

      y=top+translationY;

      但是注意view在平移的时候view的left和right几个数值是不会发生变化的。


2:MotionEvent

     分为MotionEvent.ACTION_DOWN  MotionEvent.ACTION_MOVE

      MotionEvent.ACTION_UP 

      通过MotionEvent对象我们可以得到点击事件发生的x和y坐标

       getX  getY  相对于view的左上角的x和y坐标

       getRawX getRawY相对于手机屏幕左上角的x和y的坐标



3:TouchSlop是系统可以识别的滑动的最小距离,当滑动之间的距离小于这个常量的时

     候,系统不认为他是一个滑动,获取这个常量的方法就是

      ViewConfiguration.get(getContext()).getScaledTouchSlop();


4:   VelocityTracker速度跟踪,水平方向和竖直方向的速度

      使用很简单在view的onTouchEvent方法里面跟踪,

      VelocityTracker velocityTracker=VelocityTracker.obtain();

      velocityTracker.addMovement(event);

      当我们希望知道滑动速度的时候,需要

      velocityTracker.computeCurrentVelocity(1000);  1000表示1000ms

      int xVelocity= velocityTracker.getXVelocity();

      int yVelocity= velocityTracker.getYVelocity();

      最后当我们不需要他的时候将其释放了

      velocityTracker.clear(); 

      velocityTracker.recycle();



      



   






 

      


































相关文章:

  • 2022-02-18
  • 2021-06-09
  • 2021-10-09
  • 2023-01-29
  • 2021-11-24
  • 2021-10-06
  • 2021-09-18
猜你喜欢
  • 2021-06-14
  • 2022-01-08
  • 2021-06-07
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2023-04-04
相关资源
相似解决方案