navigationdrawer Android的文件和navigationDrawerActivity的区别 [英] Difference between navigationdrawer Android Doc and navigationDrawerActivity

查看:225
本文介绍了navigationdrawer Android的文件和navigationDrawerActivity的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个抽屉式导航栏,并试图了解它是如何工作。我已经测试,我们可以在Android的工作室与activity_main如下选择navigationDrawerActivity:

I want to implement a navigation drawer, and try to understand how it works. I have tested the navigationDrawerActivity that we can choose in Android Studio with an activity_main as following :

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

和看DOC安卓的http://developer.android.com/intl/es/training/implementing-navigation/nav-drawer.html,该activity_main是:

And looking at the doc Android : http://developer.android.com/intl/es/training/implementing-navigation/nav-drawer.html, the activity_main is :

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

所以我不明白为什么它的Andr​​oid工作室和DOC之间是不同的。你能告诉我为什么会有这种差异?和DOC使用的片段,而Android的工作室活动不。

So I don't understand why it's different between android studio and the doc. Can you tell me why is there this difference? And the doc uses fragment, whereas the android studio activity doesn't.

推荐答案

本文档只是提供了一种方法来演示如何简单地 DrawerLayout 的作品,所以您将学习如何使用基本的东西像创建抽屉,处理导航点击次数和打开/关闭抽屉。

The doc just provides a way to demonstrate how simply DrawerLayout works, so you will learn how to use basic stuff like creating the drawer, handle navigation clicks and open/close the drawer.

activity_main 来自Android的工作室,不仅如此,它也带来了一些材料设计到您的应用程序。的东西,如 NavigationView AppBarLayout 他们都来自的 Android设计支持库。但是,使用 DrawerLayout 或多或少是一样的。

The activity_main comes from Android Studio is not only that, it also brings some material design to your app. Stuff like the NavigationView, AppBarLayout they all come from Android Design Support Library. But the usage of DrawerLayout is more or less the same.

这篇关于navigationdrawer Android的文件和navigationDrawerActivity的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆