Tom Taylor
Tom Taylor

Reputation: 3540

What is the difference between layout-sw801dp and layout-v21?

When I have a device with 900dp and when I'm running on api level 21+ when a layout file is present under all these folders,

res/layout/
res/layout-sw801dp/
res/layout-v21/

Which one would get picked up and why?

Upvotes: 1

Views: 124

Answers (1)

Cheticamp
Cheticamp

Reputation: 62831

Take a look at the Android App Resources Overview specifically providing alternate resources. Table 2 describes the available resource qualifiers. It is stated there that

Table 2 lists the valid configuration qualifiers, in order of precedence...

So, looking at that list, you have resources defined in the following directories:

res/layout/: defaults
res/layout-sw801dp/ : smallest width
res/layout-v21/ : version 21 and above

The priority order is as ffollows and the search for the resource will stop at the first match.

res/layout-sw801dp/
res/layout-v21/
res/layout/

Since your screen has a width of 900dp, the search for the resource would stop at res/layout-sw801dp since 900dp >= 801dp. If the screen width were 700dp (<801dp) and the API level 21+, the search would stop at res/layout-v21/. If the version were, say API 18 and the screen width 700dp then res/layout/ would be used.

Upvotes: 1

Related Questions