I've created a gallery of images and everything works fine. To zoom in and move an image is required
ImgView.setScaleType (ImageView.ScaleType.MATRIX)
and when I do it, the image I got is small, so I called the method
scaleFactor = view.getWidth()/(float)view.getDrawable().getIntrinsicWidth();
matrix.setScale(scaleFactor, scaleFactor);
so do not miss the image size but as you can see, the image rises above everything and need to stay in the center of the screen.
I tried this
matrix.postTranslate((screen_width-image_width)/2, (screen_height-image_height)/2);
but don't work.
Any idea? Sorry for not inserting images, but I can not because my reputation. Thank you very much in advance
Ok, I've corrected the error, just had to put the following lines of code:
RectF drawableRect = new RectF(0, 0, image_width, image_height);
RectF viewRect = new RectF(0, 0, screen_width, screen_height);
matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
Hopefully someone help, thank you very much for answering.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
screenWidth = layout.getWidth();
screenHeight = layout.getHeight();
Log.e("", "Image Width : " + imageWidth + " > " + imageHeight);
Log.e("", "screen Width : " + screenWidth + " > " + screenHeight);
RectF drawableRect = new RectF(0, 0, imageWidth, imageHeight);
RectF viewRect = new RectF(0, 0, screenWidth, screenHeight);
matrix.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);
img.setImageMatrix(matrix);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With