来自支持库与设计库的导航抽屉
Navigation Drawer from support library vs. design library
如 Support Library Features 页面所述; v4 支持库 通过添加 DrawerLayout
和 Design 支持库[=24] 添加了对 Navigation Drawers 的支持=] 通过添加 NavigationView
添加对导航抽屉的支持(作为对它作为依赖项的 DrawerLayout
的补充)。
有很多教程如何仅使用 v4 支持库创建导航抽屉,例如Google page on Navigation Drawer.
由于设计支持库添加了对 API 级别 7 的支持,创建导航抽屉的推荐和首选方法是什么。差异在哪里?是否存在设计差异?
NavigationView represents a standard navigation menu for your app and it follows the Material Guidelines.
NavigationView
通常放在里面一个DrawerLayout
.
当然你可以在 DrawerLayout
.
里面使用你喜欢的布局
有关 NavigationView
here 的更多信息。
what is the recommended and preferred way to create a Navigation
Drawer. Where are the differences? Are there design differences?
实际上,这些都没有什么大的 differences.for 例子,正如 Google
文档所说:
http://developer.android.com/training/implementing-navigation/nav-drawer.html
For example, the following layout uses a DrawerLayout with two child
views: a FrameLayout to contain the main content (populated by a
Fragment at runtime), and a ListView for the navigation 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">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<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="#111"/>
</android.support.v4.widget.DrawerLayout>
但在 Support Library
中,您可以使用 NavigationView
轻松实现此目的,当然使用 标准 Material 设计指南 像这样:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!--Contents like Coordinator Layout-->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:menu="@menu/drawer" />
<!--Here is the Drawer menu-->
</android.support.v4.widget.DrawerLayout>
在这种情况下,我们使用 app:menu="@menu/drawer"
以简单易行的方式实现,在上面的代码中,他们使用 <ListView
.
就这些了。
如 Support Library Features 页面所述; v4 支持库 通过添加 DrawerLayout
和 Design 支持库[=24] 添加了对 Navigation Drawers 的支持=] 通过添加 NavigationView
添加对导航抽屉的支持(作为对它作为依赖项的 DrawerLayout
的补充)。
有很多教程如何仅使用 v4 支持库创建导航抽屉,例如Google page on Navigation Drawer.
由于设计支持库添加了对 API 级别 7 的支持,创建导航抽屉的推荐和首选方法是什么。差异在哪里?是否存在设计差异?
NavigationView represents a standard navigation menu for your app and it follows the Material Guidelines.
NavigationView
通常放在里面一个DrawerLayout
.
当然你可以在 DrawerLayout
.
有关 NavigationView
here 的更多信息。
what is the recommended and preferred way to create a Navigation Drawer. Where are the differences? Are there design differences?
实际上,这些都没有什么大的 differences.for 例子,正如 Google
文档所说:
http://developer.android.com/training/implementing-navigation/nav-drawer.html
For example, the following layout uses a DrawerLayout with two child views: a FrameLayout to contain the main content (populated by a Fragment at runtime), and a ListView for the navigation 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">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<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="#111"/>
</android.support.v4.widget.DrawerLayout>
但在 Support Library
中,您可以使用 NavigationView
轻松实现此目的,当然使用 标准 Material 设计指南 像这样:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!--Contents like Coordinator Layout-->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:menu="@menu/drawer" />
<!--Here is the Drawer menu-->
</android.support.v4.widget.DrawerLayout>
在这种情况下,我们使用 app:menu="@menu/drawer"
以简单易行的方式实现,在上面的代码中,他们使用 <ListView
.
就这些了。