android側滑菜單-DrawerLayout的基本使用

來源:互聯網
上載者:User

標籤: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的基本使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.