Search code examples
androidresizeontouch

Resize View in WindowManager in android


I would like to re-size my view which is created using service in Windowmanager on touch I have changed height and width it is working properly.

But I have found that params.x and params.y is not changing so it is moving at the time of resizing the view.

And for that I found this values for different situation

  • when view is small and at top left params.x = -310 params.y = -826

  • when view is small and at bottom left params.x = -364 params.y = 958

  • when view is big and at top left params.x = -253 params.y = -657

  • when view is big and at bottom left params.x = -323 params.y = 888

    and this is my code of ontouch

                        case MotionEvent.ACTION_DOWN:
                            initialX = params.width;
                            initialY = params.height;
                            initialTouchX = event.getRawX();
                            initialTouchY = event.getRawY();
                            Log.w("DOWN","X="+params.x+" Y="+params.y);
                            return true;
    
                        case MotionEvent.ACTION_MOVE:
                            params.width = (int) (initialX + (int) (event.getRawX() - initialTouchX));
                            params.height = (int) (initialY + (int) (event.getRawY() - initialTouchY));
                            Log.w("MOVE","X="+params.x+" Y="+params.y);
                            windowManager.updateViewLayout(videoLoder, params);
                            return true;
    
  • How to get params.x and params.y as change in the height and width ?

  • And how this params.x and params.y is calculated?

I have found the some sort of similar question but answered yet.


Solution

  • I have set gravity to center so this issue was raised but after seting gravity to top left all working like charm

    params.gravity = Gravity.TOP | Gravity.LEFT;
    

    Might be helpful to some one