我正在试图找出使图像随着用户的手指向左或向右拖动以及旋转角度旋转的最佳方式。
float x1 = lastEvent[0] - lastEvent[1];
float y1 = lastEvent[2] - lastEvent[3];
float degrees1 = (float)(Math.atan2(y1, x1));
float x2 = event.getX(0) - event.getX(1);
float y2 = event.getY(0) - event.getY(1);
float degrees2 = (float)(Math.atan2(y2, x2));
float degrees = (float) Math.toDegrees(degrees2-degrees1);
但它不像我想要的那样旋转..是否有任何旋转手势的听众?感谢
答案 0 :(得分:5)
/** Determine the degree between the first two fingers */
private float rotation(MotionEvent event) {
double delta_x = (event.getX(0) - event.getX(1));
double delta_y = (event.getY(0) - event.getY(1));
double radians = Math.atan2(delta_y, delta_x);
if (Constant.TRACE) Log.d("Rotation ~~~~~~~~~~~~~~~~~", delta_x+" ## "+delta_y+" ## "+radians+" ## "
+Math.toDegrees(radians));
return (float) Math.toDegrees(radians);
}
答案 1 :(得分:0)
如果您正在寻找一个好的解释,这个link非常有用。 通过使用此库,您可以创建一个包并将SandboxView,TouchManager和Vector2D类复制/过去到该包中。
然后,将FrameLayout添加到xml文件(而不是imageView)中,并将其链接到您的代码。
最后,使用以下代码将位图添加到布局:
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), mUserImgUri);
sandboxView = new SandboxView(mContext, bitmap);
sandboxView.setLayoutParams(new FrameLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
sandboxView.setVisibility(View.INVISIBLE);
frameLayout.addView(sandboxView);
} catch (IOException e) {
e.printStackTrace();
}