I read the
http://developer.android.com/guide/practices/screens_support.html.com?
but couldn’t get how to apply this, can anyone give me example with buttons and textview that how would it fit on different devices?
I read the http://developer.android.com/guide/practices/screens_support.html.com ? but couldn’t get how to apply this, can anyone
Share
It’s not as complicated as you might think. First remember that your basic layout is always designed for
mdpi, for a normal screen size with with a medium density (about 160 dpi).So when you design your layout the important part is that you don’t use px as unit when you define your layout. Instead always use
dp(Density-independent pixel) as unit as they are automatically scaled to the correct number ofpxfor the current density.Til this moment you only have one file (e.g. myLayout.xml) for all the different layout sizes (small, normal, large and xlarge). If you think that your layout should be different on a device with a xlarge display, like a tablet then you simply create another folder called
layout-xlargein the same level aslayoutand another layout file namedmyLayout.xml. You can now make changes to this file to let the layout look different on devices with a xlarge display. Perhaps you want a larger text box you you want to rearrangethe button and text box.
So as you see, it’s not that hard. Just use dp as the unit for dimensions and Android will do the rest for you.