同一个 Activity 上的两个导航抽屉
Two Navigation Drawer on same Activity
是否可以在同一个 activity 上配置两个导航抽屉,一个在左边,另一个在右边?
你可以使用抽屉布局
<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"/>
<ListView android:id="@+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
还要检查文档 https://developer.android.com/training/implementing-navigation/nav-drawer.html
确保您使用的是工具栏而不是操作栏
是的,您可以在抽屉布局中添加两个 ListView,一个列表视图应具有 gravity
start
,另一个应具有 end
。
年
可以使用两个导航抽屉
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
tools:context="PackageName.ActivityName">
<ScrollView
android:id="@+id/scrol_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- your layout -->
</ScrollView>
<!-- First navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view_main"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/navigation_main_menu"
app:headerLayout="@layout/navigation_header"/>
<!-- Second navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view_second"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
app:menu="@menu/navigation_menu"
app:headerLayout="@layout/navigation_header"/>
</android.support.v4.widget.DrawerLayout>
为了最大限度地定制化,
在您的 xml 中,您可以使用 FrameLayout 作为容器
<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">
<FrameLayout
android:id="@+id/contDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
现在在你的Activity中,你可以用任何片段替换它
getSupportFragmentManager().beginTransaction().replace(R.id.contDrawer, SideBarCustomerFragment.newInstance()).commit();
现在对于两个用户,你可以创建2个不同的片段,你可以查看我的样板代码以供参考
是否可以在同一个 activity 上配置两个导航抽屉,一个在左边,另一个在右边?
你可以使用抽屉布局
<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"/>
<ListView android:id="@+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
还要检查文档 https://developer.android.com/training/implementing-navigation/nav-drawer.html
确保您使用的是工具栏而不是操作栏
是的,您可以在抽屉布局中添加两个 ListView,一个列表视图应具有 gravity
start
,另一个应具有 end
。
年
可以使用两个导航抽屉
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
tools:context="PackageName.ActivityName">
<ScrollView
android:id="@+id/scrol_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- your layout -->
</ScrollView>
<!-- First navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view_main"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/navigation_main_menu"
app:headerLayout="@layout/navigation_header"/>
<!-- Second navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view_second"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
app:menu="@menu/navigation_menu"
app:headerLayout="@layout/navigation_header"/>
</android.support.v4.widget.DrawerLayout>
为了最大限度地定制化, 在您的 xml 中,您可以使用 FrameLayout 作为容器
<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">
<FrameLayout
android:id="@+id/contDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
现在在你的Activity中,你可以用任何片段替换它
getSupportFragmentManager().beginTransaction().replace(R.id.contDrawer, SideBarCustomerFragment.newInstance()).commit();
现在对于两个用户,你可以创建2个不同的片段,你可以查看我的样板代码以供参考