Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support different screen size in android

Tags:

android

screen

I'm developing an app in android and I have to support all different screen sizes and density. So i've created different folder for layout : layout-small layout-large and layout.

Then I've created different folder for image: ldpi, mdpi and hdpi. In all drawable folder the image must be with different size true? I ask this cause of I have a phone with screen size large and density medium, the image shown will be smaller and they will not take the right size?

like image 954
Jayyrus Avatar asked Nov 24 '11 11:11

Jayyrus


People also ask

How do I deal with different screen sizes on Android?

The best way to create a responsive layout is to use ConstraintLayout as the base layout in your UI. ConstraintLayout enables you to specify the position and size of each view according to spatial relationships with other views in the layout. All the views can then move and resize together as the screen size changes.

How do you manage different screen size?

Use “wrap_content” and “match_parent” To ensure that your layout is flexible and adapts to different screen sizes, you should use "wrap_content" and "match_parent" for the width and height of some view components.

How do I make my Android screen fit?

Open up Settings and then tap on Display. Scroll down and tap on Display size. In this new screen, drag the slider to left to shrink the display size or the right to enlarge it.


2 Answers

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-screens android:smallScreens="true"            android:normalScreens="true"            android:largeScreens="true"           android:xlargeScreens="true"           android:anyDensity="true" /> 

And also check out my SO answer.

like image 103
Uttam Avatar answered Oct 19 '22 02:10

Uttam


Beginning with Android 3.2 (API level 13), size groups (folders small, normal, large, xlarge) are deprecated in favor of a new technique for managing screen sizes based on the available screen width.



There are different resource configurations that you can specify based on the space available for your layout:

1) Smallest Width - The fundamental size of a screen, as indicated by the shortest dimension of the available screen area.

Qualifier Value: sw'dp value'dp

Eg. res/sw600dp/layout.xml -> will be used for all screen sizes bigger or equal to 600dp. This does not take the device orientation into account.


2) Available Screen Width - Specifies a minimum available width in dp units at which the resources should be used.

Qualifier Value: w'dp value'dp

Eg. res/w600dp/layout.xml -> will be used for all screens, which width is greater than or equal to 600dp.


3) Available Screen Height - Specifies a minimum screen height in dp units at which the resources should be used.

Qualifier Value: h'dp value'dp

Eg. res/h600dp/layout.xml -> will be used for all screens, which height is greater than or equal to 600dp.



So at the end your folder structure might look like this:

res/layout/layout.xml -> for handsets (smaller than 600dp available width)
res/layout-sw600dp/layout.xml -> for 7” tablets (600dp wide and bigger)
res/layout-sw720dp/layout.xml -> for 10” tablets (720dp wide and bigger)


For more information please read the official documentation:
https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
like image 44
Schwesi Avatar answered Oct 19 '22 02:10

Schwesi