How to change view's size from 4 side in Android?
Asked Answered
V

2

12

Is it possible to resize by pulling the matrix on the 4 side of the view? I can resize from a single point to a ratio like this.

Resize View

The example above works as follows:

protected boolean onTouchDown(@NonNull MotionEvent event) {
  oldDistance = (float) Math.sqrt((midPoint.x-event.getX()) * (midPoint.x-event.getX()) + (midPoint.y-event.getY()) * (midPoint.y-event.getY()));
...
}

float newDistance = (float) Math.sqrt((midPoint.x-event.getX()) * (midPoint.x-event.getX()) + (midPoint.y-event.getY()) * (midPoint.y-event.getY()));
moveMatrix.set(downMatrix);
moveMatrix.postScale(newDistance / oldDistance, newDistance / oldDistance, midPoint.x,
        midPoint.y);
handlingSticker.setMatrix(moveMatrix);

But, for example, how can I make the process of expanding on the right side like below pictures with matrix?

first second

Verine answered 16/12, 2018 at 20:5 Comment(11)
you want to increase the size of picture from all sides? or u want result that is in screenshot? which look's like increasing size from only one side ?Gluttonous
Hi @Gluttonous i want to increase size from only one side. Each side wont equal growth.Verine
handlingSticker is a ImageView ? what is the type ?Gluttonous
no its not view. Sticker codes is there -> github.com/wuapnjie/StickerView/blob/master/sticker/src/main/…Verine
@UmutADALI Did you get any solution for this ? I am also working on resize view where i can pass any view to resize and resize view will have four handles to pull .Beltran
@GhodasaraBhaumik no i'm sorry i am workin on tooVerine
@UmutADALI are you got any solution?Sabadilla
@GhodasaraBhaumik are you got any solution?Sabadilla
@BhavenShah No i didn't found any solutionBeltran
@UmutADALI Do you get any solution for this? Please share it. If you foundTwannatwattle
@AnandSavjani sorry i didn't found any solutions tooVerine
R
4

You can try following. The idea is, if you have only horizontal or only vertical scale, then you must provide actual scale for desired axis and 1 for the other axis. Checking if the scale is horizontal or vertical is a bit tricky, you can check either:

1 The first touch was near the "vertical" border of your view. Than scroll is horizontal (x axis). Otherwise its vertical (y axis).

2 If you have buttons to drag from as in the screenshot, this makes things even easier: you just need to remember which buttons the scale was initiated with.

protected boolean onTouchDown(@NonNull MotionEvent event) {
  oldDistance = (float) Math.sqrt((midPoint.x-event.getX()) * (midPoint.x-event.getX()) + (midPoint.y-event.getY()) * (midPoint.y-event.getY()));
...
}

boolean isHorizonalScale = ... // Check if the drag has been started on the "vertical" side. If no, the scale is vertical.

moveMatrix.set(downMatrix);

if (isHorizonalScale) {
    float newDistance = (float) Math.abs(midPoint.x-event.getX());
    moveMatrix.postScale(newDistance / oldDistance, 1, midPoint.x, midPoint.y);
} else if (isHorizonalScale) {
    float newDistance = (float) Math.abs(midPoint.y-event.getY());
    moveMatrix.postScale(1, newDistance / oldDistance, midPoint.x, midPoint.y);
}
handlingSticker.setMatrix(moveMatrix);
Rigmarole answered 26/12, 2018 at 2:7 Comment(2)
Yes, this is good but it works like increase height and width. means after this if I will rotate my sticker and again go to resize then this not work well or say as I want.Sabadilla
I agree with @BhavenShah. It is working but if you rotate, all enlargements or reductions are reversed. If we can solve this problem, I will accept the answer.Verine
P
-1

moveMatrix.postScale(newDistance / oldDistance, 1, midPoint.x, midPoint.y); change to moveMatrix.preScale(newDistance / oldDistance, 1);

Plumb answered 21/5, 2020 at 11:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.