我想实现一个导航抽屉,并尝试了解它是如何工作的。我已经测试了我们可以在Android Studio中使用activity_main选择的navigationDrawerActivity,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
并查看 Android 文档:http://developer.android.com/intl/es/training/implementing-navigation/nav-drawer.html http://developer.android.com/intl/es/training/implementing-navigation/nav-drawer.html,activity_main 是:
<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>
所以我不明白为什么 android studio 和文档之间有不同。你能告诉我为什么会有这种差异吗?并且该文档使用片段,而 android studio 活动则不使用。
该文档只是提供了一种方法来演示如何简单地DrawerLayout
有效,因此您将学习如何使用基本内容,例如创建抽屉、处理导航点击以及打开/关闭抽屉。
The activity_main
来自Android Studio的不仅如此,它还为您的应用程序带来了一些材料设计。像这样的东西NavigationView
, AppBarLayout
他们都来自Android 设计支持库 http://android-developers.blogspot.com/2015/05/android-design-support-library.html。但使用DrawerLayout
或多或少是一样的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)