如何正确设计/设计Android导航抽屉

Jai*_*oks 23 xml android android-listview navigation-drawer

我无法找到有关如何正确设计标准导航抽屉的任何资源.我有以下XML,我正在寻找方法来填充多个列表视图,更改listview中的文本字体等.

我试图设计类似于以下一些设计.

在此输入图像描述

我希望找到文档,指南,代码,示例或一些方向,除了引用我的设计文档.我正在寻找更多关于如何正确调整这个新的Android设计模式的实际代码,而不仅仅是它们的外观.

NavDrawer

 <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
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#ffffff"/>
 </android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

的TextView

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Loading Content ..."
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="#000000" />
Run Code Online (Sandbox Code Playgroud)

Ste*_*ett 34

您可以将任何ViewGroup(如LinearLayout)用于抽屉.它不仅限于ListView和FrameLayout.因此,您可以像绘制活动的任何其他布局一样设置抽屉视图的样式.你应该记住的唯一事情是NavigationDrawer只能有两个孩子.第一个是Activity的布局,第二个是Drawer.您可以根据自己的喜好随意设计样式!

<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
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<!-- YOUR DRAWER -->
<LinearLayout
    android:id="@+id/drawer_view"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_gravity="start">

    <!-- Use any Views you like -->
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#ffffff"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

  • 您确定您只能看到2个孩子吗?您是否可以选择开始和结束抽屉以及主视图? (2认同)
  • @ChristopherRucinski是的,这是可能的,但问题是关于正确的造型.文档中提到设计指南中只使用了一个抽屉. (2认同)