Android layout for different screen sizes

A layout you placed on your Activity is looked well on your phone that has screen size of 320 or 360 pixels wide. But it does not look good on a device that has 600 or 720 pixels of screen width. In this Android tip, I am going to show you how to prepare a layout that looks good on different screen sizes.
Now suppose that you have an EditText on your Activity. The font size, margin, and padding of the EditText will be different in different screen sizes. Android allows you to define the dimensions to be used in different screen sizes. You need to place the dimensions in different directories under the res directory. Below are directory names and the dimensions (written in the dimens.xml file) defined for each screen size (320, 360, 480, 600, 720, and 800).

- values-sw320dp

<resources>
   <!-- font size, margin, ad padding for the screen of 320 pixels wide -->
   <dimen name="font_size">16sp</dimen>
   <dimen name="margin">5dp</dimen>
   <dimen name="padding">5dp</dimen>
</resources>


- values-360dp
<resources>
   <!-- font size, margin, ad padding for the screen of 360 pixels wide -->
   <dimen name="font_size">17sp</dimen>
   <dimen name="margin">8dp</dimen>
   <dimen name="padding">8dp</dimen>
</resources>


-values-480dp
<resources>
   <!-- font size, margin, ad padding for the screen of 480 pixels wide -->
   <dimen name="font_size">18sp</dimen>
   <dimen name="margin">10dp</dimen>
   <dimen name="padding">10dp</dimen>
</resources>


-values-sw600dp
<resources>
   <!-- font size, margin, ad padding for the screen of 600 pixels wide -->
   <dimen name="font_size">19sp</dimen>
   <dimen name="margin">15dp</dimen>
   <dimen name="padding">15dp</dimen>
</resources>


-values-sw720dp
<resources>
   <!-- font size, margin, ad padding for the screen of 720 pixels wide -->
   <dimen name="font_size">20sp</dimen>
   <dimen name="margin">18dp</dimen>
   <dimen name="padding">18dp</dimen>
</resources>


-values-sw800dp
<resources>
   <!-- font size, margin, ad padding for the screen of 800 pixels wide -->
   <dimen name="font_size">21sp</dimen>
   <dimen name="margin">20dp</dimen>
   <dimen name="padding">20dp</dimen>
</resources>



Android-layout-for-different-screen-sizes

Posted by: Dara | post date: 02-13-2015 | Subject: Android Apps Development

write programming tip




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.