0

I'm new to android development and I need to develop view with some specifications

  1. move by touch
  2. scale by pinch (zoom in\out)
  3. rotation using two fingures

I've developed rotation by using these steps here but there are some issues like jumping view if one finger removed suddenly.

and for move used this code it works well but think it is issue in sudden movement.

 public static View.OnTouchListener getTouchListener(){
    View.OnTouchListener onTouchListener = new View.OnTouchListener() {
        int prevX, prevY;
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final ConstraintLayout.LayoutParams par = (ConstraintLayout.LayoutParams) v.getLayoutParams();
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    v.bringToFront();
                    prevX = (int) event.getRawX();
                    prevY = (int) event.getRawY();
                    par.bottomMargin = -8 * v.getHeight();
                    par.rightMargin = -8 * v.getWidth();
                    v.setLayoutParams(par);
                    return true;
                }
                case MotionEvent.ACTION_MOVE: {
                    par.topMargin += (int) event.getRawY() - prevY;
                    prevY = (int) event.getRawY();
                    par.leftMargin += (int) event.getRawX() - prevX;
                    prevX = (int) event.getRawX();
                    v.setLayoutParams(par);
                    return true;
                }
            }
            return false;
        }
    };
    return onTouchListener;
}

I need someone help me to get the three features together without any issues Hint: if there is library it is welcomed.

Moustafa EL-Saghier
  • 1,721
  • 1
  • 13
  • 43
  • Have you checked gitHub? it has lots of libraries probably with this implementation already. – Kristofer Mar 30 '18 at 23:06
  • @Kristofer i checked it but what i find is implemented to work on images only and i need it for a different view if there is one like this, please mention one – Moustafa EL-Saghier Mar 30 '18 at 23:09

2 Answers2

4

After long of searching about how to implement something like that, I finally found a repository on GitHub solving my issue you can find classes for doing that here

and way to use the classes is:

        yourView.setOnTouchListener(new MultiTouchListener());

in this way you can scale, zoom in/out (by pinch) and rotate the view by pinch too.

Moustafa EL-Saghier
  • 1,721
  • 1
  • 13
  • 43
1

the perfect example of what u r searching is here:see here(example)

Happy coding!

Mihir Joshi
  • 117
  • 4