简体   繁体   中英

Android drawable folder image size

I am pretty new to Android and I am doing a pet project in order for me to learn Android. Basically I want to display six images on the screen. I have noticed the drawable folders and I have 256x256px inages in the drawable-xhdpi folder. In the Nexus 5 preview in android studio it looks great but in Nexus 7 (2012 version) the images are very small and both Nexus 5 and Nexus 7 are using the drawables-xhdpi folder.

This is my code:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageMars"
    android:id="@+id/imageJupiter"
    android:src="@drawable/jupiter"
    android:contentDescription="@string/content_desc_jupiter"
    android:layout_toRightOf="@+id/imageVenus"
    android:adjustViewBounds="true"/>

How can I make the images look bigger on the Nexus 7, but without being to big for the nexus 5?

And I want the application to look good on other devices too, so I don't think that setting a fixed size for the image(70dp x 70dp for example) would work

Thank you

Best practice in Android is to provide the correct size images in each of those folders and let the system choose the best one based on the device. Supporting Multiple Screens is a must read.

Basically what happens is the system will navigate to the folder that would best satisfy its screen, if the image it needs is there, great; if not it will navigate to the next best folder and so on. If it cannot use the best for the device it will use the best you gave and try its best to make it look as good as possible. Sometimes this isn't so great. It can stretch or shrink images into an ugly state.

So again, the best thing to do is provide multiple sizes of the same image in each of the folders to get the desired results.


Edit (response to commentary):

Guess not. In Eclipse/ADT I've got

  • Nexus 4 @ 768x1280 - Normal xhdpi
  • Nexus 7 (2012) @ 800x1280 - Large tvdpi

So regardless of "larger" the fact remains that they're pulling resources from different drawable folders. The tvdpi is said to be not needed in most apps because it's somewhere between mdpi and hdpi and those folders are usually sufficient. Maybe add the tvdpi and see if it varies at all and make sure you've correctly scaled your images based on the folder.


Edit:

Alright, the behavior you're experiencing is normal - unfortunately I suppose - but I found a solution. I've personally never faced this because I learned it's better to utilize the extra area on larger screens to put more content on there.

Anyway, as if you didn't have enough drawable folders, you need another drawable folder, or three, along with more images - yeah!

In my previous edit I mentioned the "Normal" and "Large" modifiers of the drawable folders as they appear in Eclipse ADT. Well, it turns out that those are valid folders as well and certain devices with small , large , or xlarge screens will use them.

I was able to get larger images by adding another res directory titled drawable-xlarge-xhdpi ; this is for the Nexus 10. I enlarged your jupiter file to 512x512 and...

Nexus 10屏幕截图

Note: I read that this isn't a recommended solution but could not see anywhere in the Android docs that warned against it. Research may be necessary!


You should provide different image sizes for different display sizes/resolutions. That what the drawable-100w, etc folders are.

If you don't want to do that but you still want the images resized to use all the available space, you will have to do resize the ImageView elements programmatically.

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