manually select layout set?

532 Views Asked by At

In my xml, i have small, normal, large and default layout set.

I don't want device auto select layout set but i want to select base on device width's resolution.

This is my manifest.xml

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

How to set it?

1

There are 1 best solutions below

2
On BEST ANSWER

In your project's res/ directory, you would include layout folders for each screen size you support. The possible folder names would be layout-small, layout-normal, layout-large and layout-xlarge. If you omit one or more screen size folders, Android will use the next closest folder that is equal to or less than that size, and it is also recommended that you have a "default" folder simply called layout that can be used as a catch-all (recommend using this instead of layout-small). Inside each folder you would generally place an xml layout file specific to that screen size and all of the files would have exactly the same name (ex. layout-normal/my_layout.xml, layout-large/my_layout.xml, etc.).

From within your Activity's onCreate() method you would call setContentView(R.layout.my_layout), which would automatically select the correct layout from the folder matching the screen size of the device.

Here is a very comprehensive document that explains designing applications for different screen sizes, includes the information mentioned above.