1

I'm working on a toy app which has different layout files for phones and tablets but in tablet mode it doesn't use the correct layout in layout-sw600dp folder. Here are my files contents:

activity_main.xml in layout-sw600dp folder:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:divider="?android:attr/dividerHorizontal"
    android:orientation="horizontal"
    tools:context="com.example.android.sunshine.app.MainActivity">

    <!--
    This layout is a two-pane layout for the Items master/detail flow.
    -->

    <fragment
        android:id="@+id/fragment_forecast"
        android:name="com.example.android.sunshine.app.ForecastFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
        tools:layout="@android:layout/list_content" />

    <FrameLayout
        android:id="@+id/weather_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="4" />

</LinearLayout> 

activity_main.xml in layout folder:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment_forecast"
    android:name="com.example.android.sunshine.app.ForecastFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    tools:context="com.example.android.sunshine.app.ForecastFragment"
    tools:layout="@android:layout/list_content" />

onCreate method in MainActivity.java:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mLocation = Utility.getPreferredLocation(this);
    setContentView(R.layout.activity_main);

    if(findViewById(R.id.weather_detail_container) != null)
    {
        mTwoPane = true;

        if(savedInstanceState == null)
        {
            getSupportFragmentManager().beginTransaction().replace(R.id.weather_detail_container, new DetailActivityFragment(),DETAILFRAGMENT_TAG).commit();
        }
    }
    else
    {
        mTwoPane = false;
    }
}

I'm using emulated Nexus 10 to test the app. When the app comes up it shows the single pane layout, the same as phone view. I don't know what is going wrong here.

I also tried with emulated Nexus 7 and still the problem exists.

Amazingly I tried with Samsung Galaxy Note 10.1 API 16 real device and the layout works perfectly. Is there any issue with the emulated device that causes the problem?

EDIT

I suspected that there is something wrong with emulated device and tried to emulate Samsung Galaxy Note 10.1 API 16. The layout works fine on the emulated version of the device too.

I tried to also use API 16 with emulated Nexus 7 but still I got the single pane layout. Is there something wrong with Nexus 7 & 10 with layout-sw600dp folder?

Pooya
  • 6,083
  • 3
  • 23
  • 43

1 Answers1

0

Yes, this is the issue with emulator.

Straight solution - don't use Nexus skin.

I tested various configs: Nexus 9 should work fine.

Almost in all Android courses (topic: fragments, two pane mode) in forums you can find complains about this issue.

SO questions: 1, 2.

There are some questions in the android issue tracker: 1, 2.

The issue is old and there is no official responses.

Community
  • 1
  • 1
Maxim G
  • 1,479
  • 1
  • 15
  • 23
  • can you share some references to prove this? – Pooya Apr 25 '16 at 10:59
  • Had the same issue ...empirically... You can test it by yourself. – Maxim G Apr 25 '16 at 11:05
  • if you read my "EDIT" section, I mentioned with some devices it works and with others it doesn't, I'm actually looking for the reason of that – Pooya Apr 25 '16 at 11:06
  • Did you try same configurations but without Nexus skin? – Maxim G Apr 25 '16 at 11:09
  • I don't remember as this was quite while ago but will test and let you know – Pooya Apr 25 '16 at 11:10
  • IMO this a very good tutorial and I often encounter some good challenges when reading through it which I haven't encountered before when developing other programs – Pooya Apr 25 '16 at 11:20
  • apparently it is the nexus skin for 7 & 10 that causes the problem, have you found any documentations regarding this? – Pooya May 03 '16 at 07:10