2 Finger Rotation gesture listener in android

本小妞迷上赌 提交于 2019-12-05 18:31:17
user430926
/** 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);
    }

This link is very useful if you are looking a good explanation. By Using this library, you can create a package and copy/past SandboxView, TouchManager and Vector2D classes into that package.

Then, add FrameLayout into your xml file (instead of imageView) and link it to your code.

Finally, add bitmap to the layout by using following code:

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();
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!