-1

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?

Alan Lai
  • 1,094
  • 7
  • 18
  • 41
  • If possible, use the [new size qualifiers](http://developer.android.com/guide/practices/screens_support.html#NewQualifiers), as described by the link pointed out by @happydude. For older devices, use the `small`/`normal`/`large`/`xlarge` identifiers. Alternatively, I have seen some companies (e.g. Pioneer) using a conditional statement around `setContentView(...)` in activities. However, I strongly recommend to *not* go into that direction... – MH. May 30 '12 at 21:15

1 Answers1

0

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.

happydude
  • 3,869
  • 2
  • 23
  • 41
  • Actually i want to know if i put `padding = 30dp`, The device will auto set 30dp for all type of screen size? or need manually set different numbers of `dp`? – Alan Lai May 30 '12 at 05:19
  • DP is not related to screen SIZE (length/width), but actually to screen DENSITY (how small individual pixels are). In response to your question however, 30dp will appear the same on any screen (approx. 3/16 of an inch) regardless of size OR density, and setting a padding of 30dp on a view will automatically work for all as well. – happydude May 30 '12 at 05:57