2014-05-13 50 views
2

如何創建一個像Google+的導航抽屜,其中有用戶個人資料信息標題和listview以下?像Google+一樣的導航抽屜

Custom navigation drawer

我在我的活動下面的代碼:

<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" 
    tools:context="com.br.app.MainActivity"> 
    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <fragment android:id="@+id/navigation_drawer" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:name="com.br.app.NavigationDrawerFragment" /> 

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

目前,NavigationDrawerFragment只包含一個ListView,但我嘗試添加的RelativeLayout作爲容器內的RelativeLayout創建配置文件區域和下面的列表視圖,但應用程序崩潰。

我已閱讀教程from,但據我所知,我的標題將是listview的一個項目,它不會固定在頂部(不滾動)。

如何創建像Google+這樣的自定義導航抽屜?

回答

0

一旦你知道如何實現它,你可以輕鬆地自定義android導航抽屜。這裏是一個不錯的tutorial你可以在其中設置它。

這將是你mainXML的結構:

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- Framelayout to display Fragments --> 
    <FrameLayout 
     android:id="@+id/frame_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <!-- Listview to display slider menu --> 
    <ListView 
     android:id="@+id/list_slidermenu" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="right" 
     android:choiceMode="singleChoice" 
     android:divider="@color/list_divider" 
     android:dividerHeight="1dp"   
     android:listSelector="@drawable/list_selector" 
     android:background="@color/list_background"/> 
    </android.support.v4.widget.DrawerLayout> 
3

其實,有兩個版本,由谷歌的導航抽屜。

第一個是舊的導航抽屜在下面的動作欄。例如,它在Google Play商店和Google圖書中使用。
HERE你可以找到一個實現它的庫。

第二個是在Material Design guidelines中顯示的抽屜位於操作欄上方的新導航抽屜。
HERE你可以找到一個實現它的庫。

其實這兩個庫都在開發中。但目前它們幾乎可用。

+0

謝謝你,非常有幫助的評論! –