【问题标题】:Navigation drawer like Google+Google+ 之类的导航抽屉
【发布时间】:2016-05-18 22:36:33
【问题描述】:

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

我的 Activity 中有以下代码:

<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+ 一样创建自定义导航抽屉?

【问题讨论】:

    标签: android navigation-drawer


    【解决方案1】:

    其实google使用的导航抽屉有两个版本。

    第一个是操作栏下方的旧导航抽屉。例如,它用于 Google Play Store 和 Google Books。
    HERE你可以找到实现它的库。

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

    实际上这两个库正在开发中。但此时它们几乎可以使用。

    【讨论】:

    • 谢谢,非常有帮助的评论!
    【解决方案2】:

    一旦您知道它是如何实现的,您就可以轻松地自定义 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>
    

    【讨论】:

      猜你喜欢
      • 2012-07-07
      • 1970-01-01
      • 2016-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多