2

Я недавно начал делать новое приложение. Сейчас я делаю меню. У меня есть пункты выбора города, они должны быть посередине и пункт настройки, который должен быть внизу: введите сюда описание изображения

Я делаю меню вот так:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group
        android:id="@+id/cities"
        android:checkableBehavior="single">
        <item
            android:id="@+id/town_1"
            android:title="Town 1" />
        <item
            android:id="@+id/town_2"
            android:title="Town 2" />
    </group>

    <item
        android:id="@+id/settingsMenu"
        android:title="@string/settings"
        android:icon="@drawable/ic_settings"/>

</menu>

А применяю меню вот так:

<androidx.drawerlayout.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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/dlMain"
android:fitsSystemWindows="true"
tools:context=".ui.activities.main.MainActivity">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/main_background">

    ...

</androidx.constraintlayout.widget.ConstraintLayout>

<com.google.android.material.navigation.NavigationView
    android:id="@+id/nvMain"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:menu="@menu/main_menu"/>

Кто знает как изменять положение отдельных пунктов меню?

1 ответ 1

2

Вы можете вложить в ваш Navigation свой Layout и там расположить что угодно и как угодно:

<android.support.design.widget.NavigationView
        android:id="@+id/navi_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start|top">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            // вот тут распологайте свои  View как угодно
        </LinearLayout>
</android.support.design.widget.NavigationView> 
3
  • а если это должен быть тоже пункт меню, который будет вести в другой фрагмент, то как реализовать что бы пункт подсвечивался когда виден этот фрагмент? Менять бэкграунд пункта вручную?
    – DenBondd
    4 июн 2020 в 22:38
  • @DenBondd, это уже отдельный вопрос. В любом случае вручную - это не правильное слово. Программно можно выставить. 5 июн 2020 в 3:26
  • Отслеживаете какой фрагмент выбран в данный момент и программно задаёте нему формат выделения 5 июн 2020 в 4:02

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.