I've found following code in slidingmenu library examples, in ResponsiveUIActivity.java, I don't know what is if (findViewById(R.id.menu_frame) == null) { mean:
// check if the content frame contains the menu frame
if (findViewById(R.id.menu_frame) == null) {
setBehindContentView(R.layout.menu_frame);
getSlidingMenu().setSlidingEnabled(true);
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
// show home as up so we can toggle
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} else {
// add a dummy view
View v = new View(this);
setBehindContentView(v);
getSlidingMenu().setSlidingEnabled(false);
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
}
the R.id.menu_frame points to 3 layouts
this one is in layout folder:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
this one is in layout-xlarge folder:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:orientation = "horizontal"
android:baselineAligned = "true">
<FrameLayout
android:id = "@+id/menu_frame"
android:layout_width = "0dp"
android:layout_height = "match_parent"
android:layout_weight = "1" />
<FrameLayout
android:id = "@+id/content_frame"
android:layout_width = "0dp"
android:layout_height = "match_parent"
android:layout_weight = "2" />
</LinearLayout>
and this one is in layout-large-land folder:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/menu_frame"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
in 3 of above layouts menu_frame is null but how sliding menu works with theme ?
The layout directories
layout,layout-xlarge, andlayout-large-landindicates the different layouts for supporting screen size and screen orientation. You can read more about it here.The condition,
if(findViewById(R.id.menu_frame) == null)is checking if theviewexists or not.That is, if the condition holds
true, it indicates that the sliding menu is currently closed and thus you're placing themenu view"behind" thecurrent view. However, when the condition isfalse, it indicates that the user has tapped on the menu button on the top-left corner and thus executes theelsepart, which places thecurrent view"behind" and brings up themenu view.