Два Навигационных Ящика на одной Активности
Можно ли настроить два Навигационных Ящика на одном и том же упражнении, одно слева, а другое справа?
3 ответа
Решение
Вы можете использовать макет ящика
<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
Убедитесь, что вы используете панель инструментов, а не панель действий
Да
Можно использовать два навигационных окна
<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>
Да, вы можете добавить два ListView в ваш макет ящика, один список должен иметь gravity
start
и другие имеют end
,
Для максимальной настройки в вашем 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>
Теперь в своей деятельности вы можете заменить его любым фрагментом
getSupportFragmentManager().beginTransaction().replace(R.id.contDrawer, SideBarCustomerFragment.newInstance()).commit();
Теперь для двух пользователей вы можете создать 2 разных фрагмента. Вы можете проверить мой шаблонный код для справки.