0

I need 3 different layouts for my app

  • phone/tablet portrait (layout, layout-sw600dp-port)
  • phone landscape (layout-land)
  • table landscape (layout-sw600dp)

How can I achieve to use some layout files in layout-sw600dp-port without copying the layout file?

(I know there was an option to reference layout files - not the include tag - but I can't find the documentation about it. It was possible to create all files in layout and only set a reference in e.g. layout-sw600dp)

mars3142
  • 2,501
  • 4
  • 28
  • 58
  • Yeah, I found the solution in another stackoverflow post - http://stackoverflow.com/a/17926619/708157 – mars3142 Aug 11 '15 at 12:57
  • 1
    "How can I achieve to use some layout files in layout-sw600dp-port without copying the layout file?" -- the only reason you would put anything in `layout-sw600dp-port` is if it is somehow different than `layout`. Also, `layout-sw600dp` is not landscape. If you use `layout`, `layout-land`, and `layout-w600dp` (**not** `layout-sw600dp`) as your mix of resource set qualifiers, you probably do not need to even think of duplicating layouts in the first place. – CommonsWare Aug 11 '15 at 12:59
  • @CommonsWare Why isn't `layout-sw600dp` landscape, if I use `layout-sw600dp-port`? I didn't understand this folders-logic. - Edit: Ah, I should remove the `s` from the qualifier. Clever. – mars3142 Aug 11 '15 at 13:03
  • "Why isn't layout-sw600dp landscape" -- all it says is that the smallest width, in any orientation, is 600dp or larger. "I use layout-sw600dp-port" -- IMHO, mixing an orientation (`land`/`port`) with `sw...dp` is a code smell, indicating that you should probably be using other qualifiers. `layout-w600dp` says that the *current width* (taking orientation into account) is 600dp or larger. This lines up better with the responsive design approaches seen in Web development, where you usually adjust CSS rules based on browser/viewport current width. – CommonsWare Aug 11 '15 at 13:08
  • @CommonsWare Okay, I see (because I tested it). But what is the best `layout-wXXXdp` for 7" and 10" in landscape mode? I used **w600dp** and with that configuration my Galaxy Tablet (1280x800) always uses the `layout-w600dp` folder. – mars3142 Aug 11 '15 at 13:20
  • "But what is the best layout-wXXXdp for 7" and 10" in landscape mode?" -- IMHO, that's not a useful question. Worry less about 7"/10" and more about at what point(s) your design needs to change. "I used w600dp and with that configuration my Galaxy Tablet (1280x800) always uses the layout-w600dp folder" -- there are dozens of "Galaxy Tablet" models, with various screen densities, which determines how many dp wide those devices will be for each orientation. If yours is `mdpi`, then it is 1280dp x 800dp, and it will use `layout-w600dp` resources over `layout` resources in both orientations. – CommonsWare Aug 11 '15 at 13:26
  • 1
    You may wish to peek at [Google's documentation regarding configuration examples](http://developer.android.com/guide/practices/screens_support.html#ConfigurationExamples). – CommonsWare Aug 11 '15 at 13:27

1 Answers1

1

You can use aliases. For each type you can, for example, create a file called "layout.xml". There you can have a reference to a real file. It looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>

  <item name="my_alias_layout_name" type="layout">@layout/my_concrete_layout</item>

</resources>

Put this layout file to each type of folder/ resolution you need.

Thomas R.
  • 7,988
  • 3
  • 30
  • 39