Android Image Sizes

I start with Android development, and I have a few questions about supporting different screen sizes. I read all about it here , but still not getting how to use images of different sizes for different screens. My situation is that I set the image to res / drawable / hdpi, which will be picked up on launch on my iPhone 4g for Samsung, as well as on my Galaxy 10.1 tablet. Since they have the same density class, the image will have approximately the same physical size on both devices. And this is the problem, obviously, I want the image to be larger on my tablet, but I have not yet found a way to do this.

I looked at another classification with small, medium and large, but it seems that this only applies to layouts, not image resources.

Any pointers would be appreciated.

Thanks!

+4
source share
3 answers

After posting images, for example,

/res/layout-480x800` - if you know resolution /res/layout-w480dp - if you know witdh /res/layout-h800dp - if you know height 

Android automatically selects a picture for you. Just put the image in permissions, but with the same name in these subfolders. Then just use (without qualifiers):

 android:src="@drawable/background" 

or

 imageView.setImageResource(R.drawable.background); 

The priority order of qualifiers can be found in the documentation (Table 2)

+1
source

These two devices do not have the same density. Samsung Infuse - hdpi, Galaxy Tab 10.1 - mdpi.

In addition, you usually do not want the image to be larger on the tablet. Think - if I have a list of contacts in my application, I want them to be the same height on the phone or tablet, because there is no need to raise them (this height is sufficient to display the text and the ability to touch it with your finger), but rather I want I used extra space to display more of them.

If you really need an image that is larger on the tablet than on the phone, you will need to explain more about what you are actually trying to accomplish. For example, maybe this is a background image? In this case, perhaps what you are looking for is just to stretch the image to fill the screen. (And keep in mind that making background images on Android is difficult, because you need to deal with a wide variety of screen sizes that you will fit. To avoid insanity, background images should usually be very abstract so stretching works well Look at the background images used in Android 3.0 and 4.0 for standard themes as an example.)

If you are writing a game, this is a completely different world, and you should consider whether you want to use density-based resources at all. As a rule, games will have resources that are independent of density, and just have a playing field for the game, filling the screen, and are happy with the result, which will be more on the tablet.

+7
source

Tablets are usually xhdpi, not hdpi. So, for your Samsung Infuse, put the image in:

 /res/drawable-hdpi/ 

And for the tablet, put it in:

 /res/drawable-xhdpi 

When setting the image resource through

 android:src="@drawable/image" 

or

 imageView.setImageResource(R.drawable.image); 

He will select the appropriate image based on the density of the device.

0
source

Source: https://habr.com/ru/post/1384524/


All Articles