如何正确设计/风格 Android Navigation Drawer [英] How to properly design/style a Android Navigation Drawer
问题描述
我找不到有关如何正确设计标准.我正在寻找更多关于如何正确适应这种新的 Android 设计模式的实际代码,而不仅仅是关于它们外观的想法.
导航抽屉
<框架布局android:id="@+id/content_frame"android:layout_width="match_parent"android:layout_height="match_parent"/><列表视图android:id="@+id/left_drawer"android:layout_width="240dp"android:layout_height="match_parent"android:layout_gravity="开始"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"机器人:重力=center_vertical"android:minHeight="?android:attr/listPreferredItemHeightSmall"机器人:paddingLeft =16dp"机器人:paddingRight="16dp"android:text="加载内容..."android:textAppearance="?android:attr/textAppearanceListItem"android:textColor="#000000"/>
您可以将任何 ViewGroup 像 LinearLayout 一样用于您的 Drawer.它不限于 ListView 和 FrameLayout.因此,您可以像 Activity 的任何其他布局一样设置 Drawer View 的样式.您应该记住的唯一一件事是 NavigationDrawer 只能有两个孩子.第一个是您的活动布局,第二个是抽屉.随意设计您喜欢的样式!
<框架布局android:id="@+id/content_frame"android:layout_width="match_parent"android:layout_height="match_parent"/><!-- 你的抽屉--><线性布局android:id="@+id/drawer_view"android:layout_width="240dp"android:layout_height="match_parent"机器人:方向=垂直"android:layout_gravity="开始"><!-- 使用您喜欢的任何视图 --><列表视图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>
Im having trouble find any resources on how to properly design a standard Navigation Drawer. I've got the below XML and am looking for ways to Populate multiple listviews, change font of text in listview etc.
Im trying to design similar to some of the following designs.
Im looking to find documents, Guides, code, examples or some direction besides referencing me to the Design doc . Im looking for more actual code on how to properly adapt this new Android Design pattern not just idea's of how they could look.
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>
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" />
You can use any ViewGroup like a LinearLayout for your Drawer. It is not limited to a ListView and a FrameLayout. Because of this you can style your Drawer View like any other layout of an Activity for example. The only thing you should keep in mind is that the NavigationDrawer can have only two childs. The first is your layout for the Activity and the second is the Drawer. Feel free to style them as you like!
<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>
这篇关于如何正确设计/风格 Android Navigation Drawer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!