Вопрос

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.

Это было полезно?

Решение 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

Другие советы

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;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top