Android, slidingmenu, responsivity fragment

183 views Asked by At

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 ?

1

There are 1 answers

5
Joel Fernandes On BEST ANSWER

The layout directories layout, layout-xlarge, and layout-large-land indicates 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 the view exists or not.

That is, if the condition holds true, it indicates that the sliding menu is currently closed and thus you're placing the menu view "behind" the current view. However, when the condition is false, it indicates that the user has tapped on the menu button on the top-left corner and thus executes the else part, which places the current view "behind" and brings up the menu view.