1:drawerlayout类作为父控件 出现在最顶层。
2:被包裹的二级布局就可以是 侧滑栏或者是页面本身。
3:只要是在耳机布局的gravaty——layout属性声明一个start属性,即可实现策侧滑效果。
下面贴代码:
<android.support.v4.widget.DrawerLayout 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"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/gray_background" android:fitsSystemWindows="false" android:orientation="vertical" tools:context="com.safe.peoplesafety.Function.home.HomeActivity"> <android.support.v4.view.ViewPager android:id="@+id/home_vp" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> <RadioGroup android:id="@+id/home_rg" android:layout_width="match_parent" android:layout_height="50dp" android:background="#ffffff" android:orientation="horizontal"> <RadioButton android:id="@+id/home_rg_1st_rb" style="@style/style_home_activity_bottom_rb" android:drawableTop="@drawable/home_tab_1st_icon" android:text="@string/home_page_1st" /> <RadioButton android:id="@+id/home_rg_2nd_rb" style="@style/style_home_activity_bottom_rb" android:drawableTop="@drawable/home_tab_2nd_icon" android:text="@string/home_page_2nd" /> <RadioButton android:id="@+id/home_rg_3rd_rb" style="@style/style_home_activity_bottom_rb" android:drawableTop="@drawable/home_tab_3rd_icon" android:text="@string/home_page_3rd" /> </RadioGroup> </LinearLayout> <include layout="@layout/fragment_home_left_item"/> </android.support.v4.widget.DrawerLayout>
倒数第二行就是侧滑菜单,点进去是这样的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="280dp" android:layout_gravity="start" android:background="@color/white" android:layout_height="match_parent">
可以看到的是layout_gravity属性是start。这儿决定了这个菜单是个侧滑菜单。