创建导航 抽屉的建议和首选方法是什么。差异在哪里?有设计差异吗?
其实,这些都没有什么大的differences.for例如,作为Google
医生说:
http://developer.android.com/training/implementing-navigation/nav-drawer.html
例如,下面的布局采用了DrawerLayout与两个子 意见:一个FrameLayout包含主要内容(在运行时由 片段填充)和一个列表查看导航抽屉。
<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
与标准材料设计指南这样实现的:
<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
。
就是这样。
对于初学者来说,这是一个非常好的问题。:) – Mohsen