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?