Issue
I needed to add an image into my relative layout. I found a picture with a big enough resolution (1129x1489). Then I flowed these steps to input the image.
- Right click on res, new Image Asset
- Select Launcher Icons (because I wanted my image to have colour)
- On Asset Type choose Image
- Choose image path
- Give it a name and finish
The image would then be saved under mipmap like so
However, when added to the layout it was very small and became blurry when stretched (when set to either match_parent
or fill_parent
).
The code used :
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/big"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
Then I decided to just copy and paste the image into the drawable folder and simply changing the code to android:src="@drawable/big"
. Then the android emulator displayed the image properly.
My question is, what is the proper way of inserting an image like this and why did it seem like the proper image size (xhdpi) was not being chosen from the mipmap folder.
Solution
Inside your res folder, create five folders: drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi. Now, drop the appropriate image into each of the folders and in your code, use it as "@drawable/big" and it'll show up correctly.
Answered By - sindhu_sp
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.