I'm working on a feature which includes image Scale, Rotate and Translate Operations. All these operations are working fine for me.
Now, I have a requirement to check the view position relative to the parent. I have developed the below code to get the view position after scale and translate.
private fun findViewPosition(view: View) {
val left = view.left.toFloat()
val top = view.top.toFloat()
val px = view.pivotX
val py = view.pivotY
val tx = view.translationX
val ty = view.translationY
val sx = view.scaleX
val sy = view.scaleY
val rx = view.rotationX
val ry = view.rotationY
val r = view.rotation
// Getting correct value for startX and startY after scale and translate.
// After the rotation, I'm not sure how to applied the formula.
val startX = left - (view.width * sx - view.width) / 2 + tx
val startY = top - (view.height * sy - view.height) / 2 + ty
Log.w("Start", "$startX , $startY")
val endX = left + view.width + (view.width * sx - view.width) / 2 + tx
val endY = top + view.height + (view.height * sy - view.height) / 2 + ty
Log.w("End","$endX , $endY")
}
I'm facing difficulties in finding the position after Rotation of the view. If anyone can help me on this will be a great help to me.
Here is the sample code if you want to try out the code: AndroidViewScaleRotateTranslate.zip
Thank you!



