Skip to content Skip to sidebar Skip to footer

Supporting All Screen Sizes In Android?

I know this questions has been asked quite a few times. But I couldn't find the bebest possible solution to my query. I have followed every step given in the developer support of a

Solution 1:

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.

Solution 2:

If you are designing any forms go for Match Parent, dont go for hardcore pixel positions. Use Relative layout.

P.S Please tell more about your compatibility issues?

Solution 3:

Please refer these link:

Multipal screen size handling!

For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens.

      res/layout/my_layout.xml             // layout for normal screen size ("default")
      res/layout-small/my_layout.xml       // layout for small screen size
      res/layout-large/my_layout.xml       // layout for large screen size
      res/layout-xlarge/my_layout.xml      // layout for extra large screen size
      res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

      res/drawable-mdpi/my_icon.png        // bitmap for medium density
      res/drawable-hdpi/my_icon.png        // bitmap for high density
      res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

The following code in the Manifest supports all dpis.

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

Solution 4:

Please refer below link:

http://developer.android.com/guide/practices/screens_support.html

For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens. you could use different size of the layout files in res folder and also vary for drawable images based on the density..

      res/layout/my_layout.xml// layout for normal screen size ("default")
      res/layout-small/my_layout.xml// layout for small screen size
      res/layout-large/my_layout.xml// layout for large screen size
      res/layout-xlarge/my_layout.xml// layout for extra large screen size
      res/layout-xlarge-land/my_layout.xml// layout for extra large in landscape orientation

      res/drawable-mdpi/my_icon.png// bitmap for medium density
      res/drawable-hdpi/my_icon.png// bitmap for high density
      res/drawable-xhdpi/my_icon.png// bitmap for extra high density



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

    <compatible-screens><screenandroid:screenDensity="ldpi"android:screenSize="small" /><screenandroid:screenDensity="mdpi"android:screenSize="normal" /><screenandroid:screenDensity="xhdpi"android:screenSize="large" /><screenandroid:screenDensity="xhdpi"android:screenSize="xlarge" /></compatible-screens>

And followed by any activity use this lines..

android:configChanges="orientation|screenSize|keyboardHidden"

Solution 5:

If you need an absolute measure of your the screen's density you can use the following code:

Got this from somewhere sometime ago, but still relevant. Enjoy it !

DisplayMetricsmetrics=newDisplayMetrics(); 
try { 
WindowManagerwinMgr= (WindowManager)context.getSystemService(Context.WINDOW_SERVICE)        
; 
winMgr.getDefaultDisplay().getMetrics(metrics); 
} 
catch (Exception e) { 
metrics.density = 1; 
}

The value metrics.density now contains a measure of the screen's density with 160dpi density as a the 'baseline'. More info can be found here:

http://developer.android.com/reference/android/util/DisplayMetrics.html#density

Post a Comment for "Supporting All Screen Sizes In Android?"