LeNomade LeNomade - 1 year ago 62
Android Question

How to set the layout_width = screen_width ? And how to manage good size for image compared to the device?

I already read a lot of threads on stackOverflow but I didn't find what I was searching for. I already read too the official documentation but I steel have some questions.

I'm trying to insert some image in my application and I'm trying to make the layout_width to the image equals to the width screen size (in portrait).

So I make many different size for the same image and I put them in
drawable-ldpi, drawable-hdpi ....
But when I'm trying my image on the emulator (hdpi) it works fine, but when I'm trying this on my tablet (hdpi too) the image don't get all the width screen.

I would like to know if I have to do multiple drawable about the screen size ?
and so then what about the drawable about the dpi ?

I know it's possible to put some vector image but I would like to know if I can choose the layout_width like this: android:layout_width = screen width.

and why is it so important to set the density ? A big tablet can be in mdpi et a phone on hdpi... what is so important in the density ?

Answer Source

Try using android:layout_width = "match_parent" in your layout.xml this will set the width of your main layout or parent layout to stretch from one side of screen to other side of screen. setting android:layout_height = "match_parent" and android:layout_width = "match_parent" will spread the layout over whole screen (top to bottom and left to right).

AND TO SAVE TIME AND EFFORT of creating different sizes of same image and icons, you can use Android-drawable-importer plugin. With this plugin, import just 1 image and it will create different sizes (small,large,xlarge,xxlarge etc) automatically by it self.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download