標籤:code layout 表示 容器類 back 而且 效果 mic span
眼下主流App開發中,部分是以側滑菜單為主布局架構,曾經做android側滑菜單時。大多選擇使用github上的第三方開源架構SildingMenu,可是這個架構還是稍顯笨重。好訊息是google已經開源了一個側滑菜單布局組件:DrawerLayout。DrawerLayout是V4包中的組件。也是直接繼承於ViewGroup類。所以這個類也是一個容器類。使用DrawerLayout能夠輕鬆的實現抽屜效果,使用DrawerLayout的步驟有下面1幾點:
1)在DrawerLayout中,第一個子View必須是顯示內容的view,而且設定它的layout_width和layout_height屬性是match_parent.
2)第二個view是抽屜view,而且設定屬性layout_gravity="left|right",表示是從左邊滑出還是右邊滑出。設定它的layout_height="match_parent"
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawerlayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="content" /> <ListView android:id="@+id/listview" android:layout_width="80dp" android:layout_height="match_parent" android:layout_gravity="left" android:background="#FFB5C5" /> </android.support.v4.widget.DrawerLayout>
android側滑菜單-DrawerLayout的基本使用