Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i get stickerview position in layout.?? #31

Open
pateljc opened this issue Oct 1, 2018 · 1 comment
Open

How can i get stickerview position in layout.?? #31

pateljc opened this issue Oct 1, 2018 · 1 comment

Comments

@pateljc
Copy link

pateljc commented Oct 1, 2018

stickerview getX() and getY() always return 0

@AkashOpenxcell
Copy link

Hey pateljc,
You can get center x and y position using below code.
Please write this code snippet inside the StickerView class

private float positionX, positionY;

private void getCenterPoint(PointF centerPoint) {
        float[] arrayOfFloat = new float[9];
        this.matrix.getValues(arrayOfFloat);
        float f1 = 0.0F * arrayOfFloat[0] + 0.0F * arrayOfFloat[1] + arrayOfFloat[2];
        float f2 = 0.0F * arrayOfFloat[3] + 0.0F * arrayOfFloat[4] + arrayOfFloat[5];
        float f3 = arrayOfFloat[0] * this.mBitmap.getWidth() + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2];
        float f4 = arrayOfFloat[3] * this.mBitmap.getWidth() + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5];
        float f5 = f1 + f3;
        float f6 = f2 + f4;
        centerPoint.set(f5 / 2.0F, f6 / 2.0F);
    }

private float getCenterX(){
   return positionX;
}

private float getCenterY(){
   return positionY;
}

And inside overrided onTouchEvent method of StickerView class

case MotionEvent.ACTION_UP:
                PointF centerPoint = new PointF();
                midDiagonalPoint(centerPoint);
                positionX = centerPoint.x;
                positionY = centerPoint.y;

Hope you can resolve your problem via this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants