I have tried many possible ways to set a perfect background image for a layout but never got a perfect result. Let me describe you my problem. I have an image of size 2880 x 5120
pixels. I have kept the image in the xxxhdpi
folder and then loading the image using Glide
library as the background image. I am resizing the image by calculating the screen size programmatically.
Here is my following code to load image as the background image.
Glide.with(LoginActivity.this)
.load(R.drawable.login_background)
.override(screenSize[0]*2,screenSize[1])
.animate(animationObject)
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.into(backgroundImage);
screenSize()
method:
private int[] screenSize() {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return new int[]{size.x, size.y};
}
This is the actual background image:
After loading the image as the background image. I am getting the below result.
The image is not completely fitting the screen. What can be the best optimal solution to set a background image ?