2

I want to make something that is a vertical LinearLayout on the phone version of an app, a horizontal one for tablets.

The view in question is located inside a large XML file that specifies the entire view.

The naive way to do this is to just copy and paste the file from res/layout to res/layout-sw600dp. I did this and it works. However this means I know have to maintain two files if I want to make other UX changes. This is inefficient.

What is the easiest way to abstract away the LinearLayout in question?

I have looked at Custom Components but it goes farther than I would like to go. I do not want to have to make code changes for this, it should be self-contained in XML changes.

yarian
  • 5,922
  • 3
  • 34
  • 48
  • Not sure I completely understood your question, however you can create a base layout and create a container to be included in your sw600dp and layout folders. Check http://developer.android.com/training/improving-layouts/reusing-layouts.html – fedepaol Dec 11 '12 at 22:41
  • @fedepaol Aha! That's exactly what I was searching for. Thanks. You should add that as an answer. – yarian Dec 11 '12 at 22:42
  • 1
    I think you want to use the "include" feature. See http://stackoverflow.com/questions/2732682/simple-example-of-merge-and-include-usage-in-android-xml-layouts – schtever Dec 11 '12 at 22:43

1 Answers1

3

You can reuse layouts using < include > and < merge> tags.

Doing that, you can have different containers in sw600dp and layout folders including the same common layout.

Official doc here

fedepaol
  • 6,834
  • 3
  • 27
  • 34