Question

I have an Android application to show images with viewPager. The images is in fixed size, so in some Android devices they appear with an empty border according to screen size and screen resolution.

Is there and way to resize the image to fit the screen?

It's not possible to put more than one image size in project, because I have more than 500 images.

Was it helpful?

Solution 2

You should try the different scaleTypes available. The documentation can be found here and (which I prefer) here is a very nice collection of examples of what these scaleTypes look like.

If you just want your image to be stretched and do not care about losing the aspect ratio, you might want to go with scaleType: fitXY

OTHER TIPS

Bitmap scaledBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);

Scale down method

public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
        boolean filter) {
    float ratio = Math.min(
            (float) maxImageSize / realImage.getWidth(),
            (float) maxImageSize / realImage.getHeight());
    int width = Math.round((float) ratio * realImage.getWidth());
    int height = Math.round((float) ratio * realImage.getHeight());

    Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
            height, filter);
    return newBitmap;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top