view讲解

1:view的位置讲解:

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

      轴向下)

      图解见下:

      

      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();



      



   






 

      


































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值