WEB开发网
开发学院手机开发Android 开发 Android通过手势实现的缩放处理 阅读

Android通过手势实现的缩放处理

 2010-07-01 15:25:00 来源:WEB开发网   
核心提示:}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stubfloat size = event.getSize();int szi = (int) size;int dxi = szi >

}

@Override

public boolean onTouchEvent(MotionEvent event) {

// TODO Auto-generated method stub

float size = event.getSize();

int szi = (int) size;

int dxi = szi >> 12;

int dyit = ((1 << 12) - 1);

int dyi = szi & dyit;

DisplayMetrics metrics = getResources().getDisplayMetrics();

float dx = metrics.widthPixels * dxi / (float) dyit;

float dy = metrics.heightPixels * dyi / (float) dyit;

x1 = event.getX();

y1 = event.getY();

x2 = x1 + dx;

y2 = y1 + dy;

invalidate();

return true;

}

@Override

protected void onDraw(Canvas canvas) {

// TODO Auto-generated method stub

super.onDraw(canvas);

float r = (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2)

* (y1 - y2)) / 2;

r = 50 >= r ? 50 : r;

Paint paint = new Paint();

paint.setColor(Color.BLUE);

canvas.drawCircle(x1, y1, r, paint);

}

}

}

上一页  1 2 

Tags:Android 通过 手势

编辑录入:coldstar [复制链接] [打 印]
赞助商链接