Search code examples
javaandroidcanvaslayoutscale

Doesn't change coordinate child After Scale Layout Android Java


Problem: I have Custom Layout When I Scale it with following method all Child draw in right position but when i get their coordinate still they are in primary location or when i touch previous location then onClick child call it.

Question: I want know is there any easy way i can fix it by some method or it must fix it with manual way .(anyway I haven't any idea for solve this problem)

protected void dispatchDraw(Canvas canvas) {
    canvas.save();
    canvas.scale(mScaleFactor, mScaleFactor, mPivotX, mPivotY);
    super.dispatchDraw(canvas);
    canvas.restore();
}

Near one week i stuck in this problem ,any help or suggestion can be grateful.


Solution

  • When you scale using the canvas, you are changing the appearance of the view but not the underlying view. That is why when you touch what appears to be one location, the code reports a different location.

    Take a look at this question and the accepted answer. It will give you an idea about how to proceed in mapping your coordinates.

    I hope this helps.