开发者

Android conditional layouts for phones:tablets

开发者 https://www.devze.com 2023-03-19 14:16 出处:网络
I am making an app that is rea开发者_JAVA百科dily available and MOSTLY used on phones, but would be CONVENIENT to use on a tablet if available.

I am making an app that is rea开发者_JAVA百科dily available and MOSTLY used on phones, but would be CONVENIENT to use on a tablet if available.

I am familiar with landscape/portrait layouts for the separate XML files, but what about for the different resolutions? This is also an issue for phone-only applications, what is the best way to have scalable layouts.

I use the dip values which are density independent but not as effective as just using percentages that will scale your layout effectively.

I also hardcode the XML. I IMAGINE that I could programmatically generate the layout by checking the screen width and height ON EVERY ACTIVITY, but tell me there is a better way?


You can provive extra layouts by specifying the screen size (small, normal, large and xlarge) in the same way you specify layouts for portrait or landscape.

These are some examples taken from the android documentation related to this subject

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

The book The Busy Coder's Guide to Android Development has an excellent explanation about this subject.

0

精彩评论

暂无评论...
验证码 换一张
取 消