0

I read this tutorial http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts ,but I don't understand all examples.I want to create an image in my android application ,but I don't know how much pixels should I use,for example in drawable-ldpi , drawable-mdpi , drawable-hdpi and drawable-hxdpi which sizes I should use ? What means 3:4:6:8 sizes ?Is this for images or for application Icon ?

Developer
  • 49
  • 2
  • 9

1 Answers1

1

Have a look to the Android documentation:

http://developer.android.com/design/style/iconography.html

They explain what you are asking at the beginning, but I advise you to read the whole article.

If you want to generate an icon set with all the different dimensions wanted, you can use a tool named Icon Generator that you can find here:

http://android-ui-utils.googlecode.com/hg/asset-studio/dist/icons-launcher.html

This tool is also available if you are using Eclipse to develop:

  • Right-click on the Android project
  • New --> Other ...
  • Then open the Android folder and select "Android Icon Set"

Then just follow the steps to create the icons wanted, they will be automatically added in your project in your "res" folder.

Concerning the image sizes, I advise you to use "dp":

The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

Several links on the official doc:

http://developer.android.com/guide/practices/screens_support.html http://developer.android.com/training/multiscreen/screendensities.html http://developer.android.com/design/style/metrics-grids.html

Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85
  • This is so useful,but what about the images in my application not the icon? – Developer Aug 21 '13 at 14:35
  • When you define image sizes in your app, use "dp" and not "px". Using "dp" the size of the images you define will change according to the size of the screen and its density. I will add in the answer some links. – Yoann Hercouet Aug 21 '13 at 14:42
  • Yea but if I use 50dp width and 50dp height of the image in small screen it's not the same in a 10 inch screen for example ,it's too small :( – Developer Aug 21 '13 at 14:44
  • You can define for each type of screen the image that should be loaded. If you create an icon on Eclipse (using a big image) with the icon generator, you will see that it will create the same image but with different sixes in the folders "drawable-hdpi", "drawable-ldpi" etc. The system will load the right image according to the device in use. – Yoann Hercouet Aug 21 '13 at 14:49
  • Okay,right click on my project then new other and android icon set and then which what I should choose for images not for launcher icons? – Developer Aug 21 '13 at 14:58
  • This tool unfortunately only generates icons. If you want to add an image but do not want to bother creating all the sizes, you can just create an image big enough to be displayed also on large screens and place under the "drawable" folder. – Yoann Hercouet Aug 21 '13 at 15:04
  • Okay but I think the best practise is to create image with different sizes and paste this image in the differen drawable folders ,but I don't know which sizes to use,if I create a big image and how it will seems in small phones?Will it lose quality or not? – Developer Aug 21 '13 at 15:44
  • it does not lose quality, the image is just resized. – Yoann Hercouet Aug 21 '13 at 15:48
  • I just should put the image in drawable folder with a big size and then just src the same image in the differents layouts and set the height and width to wrap_content,right? – Developer Aug 21 '13 at 16:10
  • Yes just set the height and width of the image using "dp". – Yoann Hercouet Aug 21 '13 at 16:12
  • Okay thanks bro,I can't give you up because I don't have reputation :( But you helped me a lot.Thank you very much. – Developer Aug 21 '13 at 16:22