Android- Rotate image with single finger gesture

2019-02-03 19:58发布

I want to know about How to rotate the bitmap image with single touch gestures.kindly help and suggest some solutions. I done scaling the bitmap with the help of

http://grishma102.blogspot.in/2013/10/drag-and-drop-functionality-to-move.html . Now I need to rotate the whole image while touch and rotate the resize button. How to acheive it?

Thanks in advance

enter image description here

2条回答
Root(大扎)
2楼-- · 2019-02-03 20:57

function that handles rotation with one finger, the main idea is to calculate the centerX and centerY of your view and taking into consideration the status bar height if you using one.

       @Override
       public boolean onTouch(View view, MotionEvent event) { 
         switch (action) {
                case MotionEvent.ACTION_UP:
                    break;
                case MotionEvent.ACTION_DOWN:

                    rotateX = event.getRawX();
                    rotateY = event.getRawY();

                    centerX = view.getX() + ((View) getParent()).getX() + (float) view.getWidth() / 2;

                    centerY = view.getY() + statusBarHeight + (float) view.getHeight() / 2;

                    break;

                case MotionEvent.ACTION_MOVE:

                    newRotateX = event.getRawX();
                    newRotateY = event.getRawY();

                    double angle = Math.atan2(event.getRawY() - centerY, event.getRawX() - centerX) * 180 / Math.PI;

                    view.setRotation((float) angle - 45);

                    rotateX = newRotateX;
                    rotateY = newRotateY;

            }
        }

        return true;
    }
};
查看更多
甜甜的少女心
3楼-- · 2019-02-03 20:59

Check out my blogspot in which i have tried to implement the functionality of stretch the image on arrow click and also delete it, and also you can move the image on the screen using gesture.

Drag-Drop image Also check out the Demo of DragDropImage

enter image description here

查看更多
登录 后发表回答