---
title: "android view(1) 基础知识"
author: "cuixuxucui"
date: "2016-06-29T08:48:03Z"
tags: []
categories: ["编程语言"]
slug: "android-view-1"
draft: false
lastmod: "2016-06-29T10:32:01Z"
id: 2307901
url: "https://smartblack.iteye.com/blog/2307901"
---

一、view的坐标

1.top,left,right,bottom是指view相对于父容器的坐标

2.从android3.0开始，增加了x,y,translationX,translationY.这四个参数也是相对于父容器的偏移量，在平移时top和left表示原始左上角的位置信息，并不会发生改变。改变的就是这四个参数。

x = left+translationX,y = top+translationY

二、MotionEvent

1.getX/getY返回相对于当前view左上角的坐标，getRawX/getRawY返回的是相对于手机屏幕左上角的坐标。

2.在onTouchEvent中追踪滑动速度：

VelocityTracker velocityTracker = VelocityTracker.obtain();

velocityTracker.addMovement(event);

velocityTracker.computeCurrentVelocity(1000);//时间间隔毫秒

int xVelocity = (int) velocityTracker.getXVelocity();

int yVelocity = (int) velocityTracker.getYVelocity();

velocityTracker.clear();//重置

velocityTracker.recycle();//回收

三、GestureDetector实现监听双击

参考http://www.cnblogs.com/rayray/p/3422734.html