Reputation: 141
I've tested my app in some devices with different sizes, and i've got terrible style at last. i've read some documents about folder layout and sizes for customizing layouts for different sizes of phone.
So base on what i've read i've added below lines into Manifest.
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens= "true"
android:anyDensity="true"
/>
and copied layout contents to other created folders which they are :
layout-large
layout-small
layout-xlarge
layout-xlarge-land
and started to edit one of them to see the result, and nothing happend and design was same, so i thought i could be designed wrong xml folder, so base on another tutorial i've added another folder with layout-sw320dp
and it's worked but problem is now, everything is showing like 320dp folder, large and small doesn't matter. and in design view all folders are phones models sizes changed to :
Nexus One -> sw320dp\*.xml
Pixel -> sw320dp\*.xml
So what's the reason of this? and what are the sizes of these layout folders with small
and large
name exactly? and how i should make this layout work properly?
Looks like my folders are not actually related to exact sizes, 320 is overwriting on all sizes except wear android.
Upvotes: 0
Views: 308
Reputation: 54194
The swXXXdp
resource modifier means that this folder will be selected if the device's "smallest width" is XXX
dp or greater. So if you have these two directories:
res/layout/
res/layout-sw320dp/
Then any device that has a smallest width of 319dp or less will use the layout/
files, and any device that has a smallest width of 320dp or more will use the layout-sw320dp/
files. Almost every device is 320dp or more, so you'll see that almost every device uses this folder.
Modern phones tend to have around 400dp of smallest width. You can always look screen specs up online. For example, https://www.gsmarena.com/google_pixel_2-8733.php says that the Pixel 2 is 1080px wide at 441 pixels per inch; this works out to 391dp (1080 / (441/160)).
Common cutoffs for the swXXXdp
modifiers are 600dp for seven-inch tablets and 720dp for ten-inch tablets. So you might want a project structure like this:
res/layout/ <-- everything smaller than a 7" tablet
res/layout-sw600dp/ <-- 7" tablets
res/layout-sw720dp/ <-- 10" tablets
Note, though, that you can use any number you want. sw503dp
is totally valid. You'll just have to choose what numbers work well for your layouts.
As for layout-large
and layout-small
etc, just ignore those. Those are outdated, and were used before the swXXXdp
qualifier was added. Unless you're developing for extremely old API versions, you're better off just using swXXXdp
instead.
Upvotes: 2
Reputation: 1987
You're starting the layout
name with capital letter Layout-large
. Replace those letters with small case (e.g: layout-...
) and it would work.
Upvotes: 0