Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Kunal Patel
Kunal Patel
1,448 Points

Android: Different Layouts for Different Devices

Anyone know of a lesson on how to create layouts for medium phone vs. tablet displays? How to create the layout, folder naming conventions, and how Android resolves this?

I thought one exists, but I cannot seem to find it.

1 Answer

The information provided by Google is invaluable. Tons of information is available.

Definitely read through: http://developer.android.com/guide/topics/resources/providing-resources.html

and: http://developer.android.com/guide/practices/screens_support.html

As a quick little tutorial: Try putting a completely different .xml layout into res/layout-sw600dp/ and run your application on different screen sizes.

Also, I recommend watching the Android Developers channel on youtube. This video may also help get the point across: http://www.youtube.com/watch?v=wON8StzwOLk

Also, don't think of it as creating "different layouts for different devices". It should be more of a "different layout for varying dpi and screen size."

Kunal Patel
Kunal Patel
1,448 Points

I just saw the youtube video, ironically they glossed over the m2Pane boolean. Any idea on how they determine this?

If you simply want to create a different layout, I would first read into how to provide resources for specific qualifiers. If you are interested in fragments (again, probably not the answer you want to hear), I recommend reading through the other documentation found here: http://developer.android.com/guide/components/fragments.html

Although using different layout qualifiers and using fragments should be a fairly easy lesson this is definitely not something you can teach through a discussion. This is really a fundamental part of how you go about developing/architecting your application, and shouldn't be taken lightly. Maybe the video wasn't the best example, but it was simply to show you how you can create a layout folder for different qualifier. Hope that helps!

EDIT: Just to make sure I answered your original questions.

How to create the layout, folder naming conventions, and how Android resolves this?

  • create the layout: This is taught in the Treehouse Android videos.
  • folder naming conventions: check out: Qualifier Rules
Kunal Patel
Kunal Patel
1,448 Points

Thank you...I've done some reading on Fragments. Ultimately I will need to figure out how to modularize my app.