Search code examples
androidandroid-layoutlayoutmaster-detail

Android Phone recognized as "Two Pane" layout


I'm writing an application that has two different layout:

  • two pane (master-detail) for tablet (screen over 820 dp)
  • single pane (master + activity) for phones (screen under 820 dp)

I'm testing my application on different devices and I have different (and unexpected) behaviours: on Samsung Galaxy Tab 4 10'' (1280x800) I get the two pane layout - as expected; but when I try it on my LG Nexus 5 (1920x1080) or LG G2 Mini (960x540) i expect to get the single pane layout, things that don't happen and I still get the two pane layout.

In my project i have a folder named values-w820p that contains the file refs.xml - as said in this guide.

Also the activity I use check if there is room for a two pane layut on method onCreate - here's the code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings_list_container);

    //some creation code

    if (findViewById(R.id.settings_detail_container) != null) {
        Log.i("Two panes", "two panes");

        mTwoPane = true;

        //some two pane handling

    }
}

Where I go wrong? Why i can't have a single pane layout on "small" screen?

EDIT: SOLVED The solution is to put the "two pane" layout under layout-large and the "single" layouts under layout.


Solution

  • I think you're confusing size with density. You can certainly have a high density small screen: that's exactly what your Nexus 5 is. If you choose a layout via density, you'll get your two-pane layout on a Nexus 5 because it's high density.

    You need to be determining the layout on screen size instead.

    See the Android docs for details, but you want values-large etc. for your folder structure.