简体   繁体   中英

About Android Image Scaling

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.

  1. Right click on res, new Image Asset
  2. Select Launcher Icons (because I wanted my image to have colour)
  3. On Asset Type choose Image
  4. Choose image path
  5. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM