LinearLayout ly_hellword = (LinearLayout) findViewById(R.id.ly_hellword);
//view左上角x轴的值
int left = ly_hellword.getLeft();
//view右下角x轴的值
int right = ly_hellword.getRight();
//view左上角y轴的值
int top = ly_hellword.getTop();
//view右下角y轴的值
int bottom = ly_hellword.getBottom();
//view宽度
int width = right - left;
//view高度
int high = bottom -top;
//view左上角xy轴坐标值(Android3.0之后添加参数)
float x = ly_hellword.getX();
float y = ly_hellword.getY();
//view左上角相对于父容器的偏移量(Android3.0之后添加参数)
float tx = ly_hellword.getTranslationX();
float ty = ly_hellword.getTranslationY();
x = left + tx;
y = top + ty;
触摸事件
ly_hellword.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
// TODO Auto-generated method stub
//点击发生的相对于当前view左上角x坐标
event.getX();
//点击发生的相对于当前view左上角y坐标
event.getY();
//点击发生的相对于手机屏幕左上角x坐标
event.getRawX();
//点击发生的相对于手机屏幕左上角y坐标
event.getRawY();
switch (event.getAction()) {
//手指接触屏幕
case MotionEvent.ACTION_DOWN:
break;
//手指在屏幕上移动
case MotionEvent.ACTION_MOVE:
break;
//手指从屏幕上松开
case MotionEvent.ACTION_UP:
break;
default:
break;
}
return false;
}
});
//系统所识别出的被认为是滑动的最小距离
frameworks/base/core/res/res/values/config.xml
int touchSlop = ViewConfiguration.get(this).getScaledEdgeSlop();