I'm trying to create a ImageView
with zoom functions.
I got the zoom function ready, but now I want the image to scale to the ImageView
when starting the Activity
. Normally I would use the ScaleType
in the xml layout,
but it needs to be Matrix
for the zoom function. How can I do this?
I tried the solution from this question: Android image view matrix scale + translate
Matrix m = imageView.getImageMatrix();
RectF drawableRect = new RectF(0, 0, imageWidth, imageHeight);
RectF viewRect = new RectF(0, 0, imageView.getWidth(), imageView.getHeight());
m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
imageView.setImageMatrix(m);
But the problem is I can't use getWidth()
and getHeight()
because its to early (it only returns 0). Is there a work around? Or how can I fix this?