How to Set Android Layout to Support All Screen Sizes

How to set android layout to support all screen sizes?

Please go through the following links. These might help you:

Supporting Different Screen Sizes

Supporting Multiple Screens

Supporting Different Densities

Supporting Tablets and Handsets

AFAIK, the only way to support all screens is by doing that folder bifurcation. Every XML file goes up to a few kilo bytes. So, size shouldn't be too much of an issue as such.

How to make an Android App Support all Screen Sizes?

Read supports-screens

If your application does not work well when resized to fit different screen sizes, you can use the attributes of the element to control whether your application should be distributed to smaller screens or have its UI scaled up ("zoomed") to fit larger screens using the system's screen compatibility mode.

 <supports-screens
android:resizeable="true"
android:smallScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:normalScreens="true"
android:anyDensity="true"/>

For more info read Screen compatibility

Supporting all screen sizes in android?

Basically some devices belongs to large or normal group but they have so much difference in height and width for example- Nexus-4 4.7" having dimensions 768x1280 and one other device 5.1" having dimensions 480x800. So you can create layouts folders depending upon height and width. For example- layout-w480dp, layout-w720dp or layout-h800dp or layout-h1280dp. Then set views in those layouts according to your requirement.

Android layouts for different screen sizes

The answer is already given by user5594218 but looks like you are still unclear. (maybe you are beginner)

So, here is the step by step guideline

Solution 1: (short and simple)

  1. Navigate to app > src > main > res

  2. Duplicate layout directory by copying and pasting

  3. Rename duplicated Directories e.g layout-sw300dp

Solution 2: (bit lengthy)

  1. Create new resource directory: res > New > Android resource directory

Create new resource directory


  1. Select Resource Type as layout

  2. Add sw<N>dp in Directory name e.g layout-sw300dp and Hit OK

Sample Image


  1. Navigate to app > src > main > res

  2. Copy layouts XML file inside new directory

    //repeat process for other qualifiers

List of Qualifiers to support all screens:

  • layout-sw300dp
  • layout-sw330dp
  • layout-sw480dp
  • layout-sw600dp
  • layout-sw720dp

Testing:

This is how it gonna look like, if you did it right.
Sample Image

For more detail and examples, check: Android Application Development All-in-One For Dummies



Related Topics



Leave a reply



Submit