释放双眼,带上耳机,听听看~!
相机放大缩小的关键代码:
private floatoldDist= 1f;
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() == 1) {
handleFocusMetering(event, camera);
} else {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = getFingerSpacing(event);
break;
case MotionEvent.ACTION_MOVE:
float newDist = getFingerSpacing(event);
if (newDist > oldDist) {
Log.e("Camera","进入放大手势");
handleZoom(true, camera);
} else if (newDist < oldDist) {
Log.e("Camera","进入缩小手势");
handleZoom(false, camera);
}
oldDist = newDist;
break;
}
}