DrawerLayout 使用


<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <include
            android:id="@id/relative_top_title"
            layout="@layout/fragment_top_title" />

        <FrameLayout
            android:id="@id/frag_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/relative_top_title" />
    </RelativeLayout>

    <LinearLayout
        android:id="@id/linear_leftmenu"
        android:layout_width="220.0dip"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="@color/white"
        android:orientation="vertical" >

         <!--左側菜單布局-->
    </LinearLayout>

    <LinearLayout
        android:id="@id/linear_rightmenu"
        android:layout_width="100.0dip"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:background="@color/white"
        android:orientation="vertical" >

         <!--右側菜單布局-->
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

 

android.support.v4.widget.DrawerLayout 做為根布局

布局格式 一個第布局是內容,第二個是左側菜單,第三個是右側菜單,通過android:layout_gravity屬性設置left和right來控件左右

布局是固定好的

因為我把左側菜單和內容順序搞返了 可以滑動打開但無法滑動關閉菜單中的所有事件點擊沒有任何反應,當時還以為要加什么屬性調試很久,最后無意把布局換了下居然好了后來搜索后才知道這個問題

//控制打開或關閉 這里是左側

if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawer(Gravity.LEFT);
} else {
mDrawerLayout.openDrawer(Gravity.LEFT);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM