StickerView icon indicating copy to clipboard operation
StickerView copied to clipboard

How can i get stickerview position in layout.??

Open pateljc opened this issue 6 years ago • 1 comments

stickerview getX() and getY() always return 0

pateljc avatar Oct 01 '18 11:10 pateljc

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.

AkashOpenxcell avatar Mar 07 '19 09:03 AkashOpenxcell