With a link for an image such as www.example.com/image.png how do I download the image and set it as the background for a fragment? Would it be an imageview that is resized to the size of the content container? How do I put an image from the web to an imageview?
Asked
Active
Viewed 111 times
0
-
2Does this answer your question? [How To Load Layout Background Using Picasso](https://stackoverflow.com/questions/31464867/how-to-load-layout-background-using-picasso) – aiqency Apr 08 '20 at 20:06
2 Answers
1
It can be an ImageView to match the fragment height/width and with the property android:scaleType="centerCrop"
. To download and show the image in that ImageView use Glide
. Here is the official documentation.

Tiko
- 851
- 8
- 15
1
To make the screen occupy fullscreen, and proper scaling adds the following properties to ImageView.
android:adjustViewBounds="true"
When we set adjustViewBounds to true we are telling the ImageView (not the drawable) to adjust its bounds to preserve the aspect ratio of its drawable. and add the scale type to imageview
android:scaleType="centerCrop"
and if get the image of same ratio passing width and height, using the thumbor libray.Here is the link for reference https://github.com/thumbor/thumbor

Ravi
- 2,277
- 3
- 22
- 37