像Google+这样的导航抽屉

时间:2014-05-13 00:31:50

标签: android navigation-drawer

如何创建像Google+这样的导航抽屉,其中有用户个人资料信息标题,下方有listview

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仅包含一个列表视图,但我尝试将RelativeLayout作为具有内部RelativeLayout的容器添加以创建配置文件区域和下面的列表视图,但应用程序崩溃。

我已经阅读了教程from,但据我所知,我的标题将是listview的一个项目,并且它不会被修复到顶部(不滚动) )。

如何创建Google +等自定义导航抽屉?

2 个答案:

答案 0 :(得分:3)

实际上,google使用了两种版本的导航抽屉。

第一个是旧的导航抽屉下面的动作栏。例如,它用于Google Play商店和Google图书。
HERE你可以找到一个实现它的库。

第二个是Material Design guidelines中显示的新导航抽屉,抽屉位于操作栏上方。
HERE你可以找到一个实现它的库。

实际上这两个库正在开发中。但它们目前几乎可用。

答案 1 :(得分:0)

一旦您知道如何实现它,您就可以轻松自定义Android Navigation抽屉。这是一个很好的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>