【问题标题】:How to properly design/style a Android Navigation Drawer [closed]如何正确设计/设计Android导航抽屉[关闭]
【发布时间】:2013-08-13 06:00:59
【问题描述】:

我很难找到有关如何正确设计标准Navigation Drawer 的任何资源。我有以下 XML,并且正在寻找填充多个列表视图、更改列表视图中文本字体等的方法。

我正在尝试设计类似于以下一些设计。

除了将我引用到 Design doc 之外,我还在寻找文档、指南、代码、示例或某些方向。我正在寻找更多关于如何正确适应这种新的 Android 设计模式的实际代码,而不仅仅是关于它们的外观的想法。

导航抽屉

 <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>

文本视图

<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" />

【问题讨论】:

  • 这里是“Android Design in Action: Navigation Drawers”youtube.com/watch?v=F5COhlbpIbY的链接。
  • 给出的示例与“他们的外观想法”有何不同?导航抽屉通常只是样式精美的ListView,因此任何关于后者的教程都应该这样做。有很多“在那里”,包括说明如何为行项目使用自定义布局的堆(这可能会让你至少走到一半)。

标签: android xml android-listview navigation-drawer


【解决方案1】:

您可以为抽屉使用任何 ViewGroup,例如 LinearLayout。它不限于 ListView 和 FrameLayout。因此,您可以像其他任何 Activity 布局一样设置 Drawer View 的样式。您应该记住的唯一一件事是 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>

【讨论】:

  • 您确定只能有 2 个子视图吗?难道你不能在主视图中同时选择开始和结束抽屉吗?
  • @ChristopherRucinski 是的,这是可能的,但问题是关于正确的样式。并且文档提到设计指南中只使用了一个抽屉。
  • 即使我使用 android:divider="@android:color/transparent" 和 android:dividerHeight="0dp",我的列表视图中仍然会出现一条白线。如何更改那条白线的颜色?
  • @Pria 要完全删除分隔符,您可以在 xml android:divider="@null" android:dividerHeight="0dp" 中设置它。
  • 可以在视图中添加片段吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多