Reputation: 1214
I am struggling for layouts for an Android app. I have defined different layouts for different screen sizes and the current layout directory structure is something like this:
Problem
The main layout directory files are being displayed for 3.7 to 7.0
which is a very broad range. And text overlap on small screens and if I adjust on small; it becomes very tiny on the large screen.
According to me, the layout small files should be rendered for smaller screens but those files are only rendered for android wear devices.
layout-xlarge seems to work for Nexus 9 to Nexus 10
I want to know, how can I define the different layout for 3.7-5.0
and 5.0-7.0
screen sizes.
Upvotes: 9
Views: 17470
Reputation: 1646
Create folders like the following
layout-sw300dp
layout-sw330dp
layout-sw480dp
layout-sw600dp
layout-sw720dp
Create also values-folders like
values-sw300dp
values-sw330dp
values-sw480dp
values-sw600dp
values-sw720dp
Upvotes: 4
Reputation:
Navigate app-> res-> layout and right click then New-> layout resource file write the filename correctly and from available qualifiers choose the size you want.
Upvotes: 1
Reputation: 2552
The answer is already given by user5594218 but looks like you are still unclear. (maybe you are beginner)
So, here is the step by step guideline
Solution 1: (short and simple)
Navigate to app > src > main > res
Duplicate layout directory by copying and pasting
Rename duplicated Directories e.g layout-sw300dp
Solution 2: (bit lengthy)
res > New > Android resource directory
Select Resource Type
as layout
Add sw<N>dp
in Directory name e.g layout-sw300dp
and Hit OK
Navigate to app > src > main > res
Copy layouts XML file inside new directory
//repeat process for other qualifiers
List of Qualifiers to support all screens:
Testing:
This is how it gonna look like, if you did it right.
For more detail and examples, check: Android Application Development All-in-One For Dummies
Upvotes: 23
Reputation: 7948
Dear you don't need to declare layout for various screen. just make single layout for every screen and don't fix the width and height of layout. you have to keep height either match parent and wrap content as well as for width.
Upvotes: 0
Reputation: 88
you should try dp in your layout-height/layout-width/textsize as it is independent of screen sizes.
Upvotes: -1