Xamarin Android Menu — фоновое изображение NavigationView и полноэкранный режим

Мне нужна помощь с меню в Android...

  • Во-первых: мне нужно в меню изображение в фоновом режиме
  • Второе: по возможности будет хорошее полноэкранное меню

Мое меню выглядит так:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:local="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fillViewport="true">
  <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    >
    <ImageView
      android:id="@+id/nav_background"
      android:src="@drawable/test_back"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:alpha="1"
      android:scaleType="centerCrop"/>
<android.support.design.widget.NavigationView 
                                              android:id="@+id/navigation_view"
                                              android:layout_height="match_parent"
                                              android:layout_width="match_parent"
                                              android:layout_gravity="end"
                                              android:theme="@style/NavigationViewStyle"
                                              android:fitsSystemWindows="true"
                                              local:itemTextColor="@color/white"
                                              android:background="@color/main_red_opacity"
                                             >

  <LinearLayout  android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_gravity="bottom"
                 android:orientation="vertical">
    <LinearLayout  
      android:layout_marginRight="30dp"
      android:layout_marginLeft="30dp"
      android:layout_marginTop="50dp"
      android:layout_marginBottom="50dp"
      android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_gravity="bottom"
                   android:orientation="vertical">
      <TextView
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:textSize="22dp"
        android:id="@+id/nav_menuItem"
        android:text="MenuItem"
        android:textColor="@color/white"
      />
      <TextView
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:textSize="22dp"
        android:id="@+id/nav_menuItem"
        android:text="MenuItem"
        android:textColor="@color/white"
      />
      <ImageView
        android:layout_marginTop="45dp"
        android:layout_marginBottom="45dp"
        android:layout_height="1dp"
        android:layout_width="match_parent"
        android:background="@color/main_gray"
        />
      <TextView
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:textSize="22dp"
        android:id="@+id/nav_menuItem"
        android:text="MenuItem"
        android:textColor="@color/white"
      />
      <TextView
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:textSize="22dp"
        android:id="@+id/nav_menuItem"
        android:text="MenuItem"
        android:textColor="@color/white"
      />
      <TextView
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:textSize="22dp"
        android:id="@+id/nav_menuItem"
        android:text="MenuItem"
        android:textColor="@color/white"
      />

      </LinearLayout>

    <ImageView
      android:layout_gravity="left"
      android:src="@drawable/logo"
      android:layout_width="match_parent"
      android:layout_height="50dp"
      android:id="@+id/logoBottom"
      android:scaleType="fitCenter" />
    </LinearLayout>

</android.support.design.widget.NavigationView>

  </RelativeLayout>
</ScrollView>

Это работает, но мне нужен макет с элементами меню в нижней части меню, но результат: введите здесь описание изображения

а без ImageView это выглядит так: введите здесь описание изображения

Это мне нужно, но с изображением в фоновом режиме...

ИЗМЕНИТЬ

  <!-- Navigation style -->
  <style name="NavigationViewStyle">
    <item name="android:textSize">18dp</item>
    <!-- menu item text size-->
    <item name="android:listPreferredItemHeightSmall">60dp</item>
    <!-- menu item height-->
  </style>

Демонстрация Github: https://github.com/pinkysek/XabluDemoApp/tree/master/XabluAppTest


person pnk    schedule 12.01.2018    source источник
comment
Пожалуйста, удалите ImageView с идентификатором nav_background и добавьте фон к вашему RelativeLayout. Пожалуйста, покажите `android:theme=@style/NavigationViewStyle`, я не знаю, в чем ваша проблема, я просто пробую ваш код, и есть некоторые ошибки в вашем макете. Я предлагаю вам отредактировать свой вопрос.   -  person Robbit    schedule 15.01.2018
comment
@JoeLv хорошо отредактировал и добавил NavigationViewStyle   -  person pnk    schedule 15.01.2018
comment
Вы хотите, чтобы ImageView с идентификатором nav_background развернулся на весь экран?   -  person Robbit    schedule 15.01.2018
comment
если возможно, я хочу, чтобы все меню было полноэкранным, поэтому вы тоже можете использовать ImageView   -  person pnk    schedule 15.01.2018


Ответы (1)


Измените RelativeLayout на FrameLayout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:local="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fillViewport="true">
  <FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
   android:background="@drawable/test_back"
    >
  </FrameLayout>
</ScrollView>

и добавьте android:layout_marginLeft="-64dp" в свой FrameLayout, идентификатор которого равен navigation_frame в макете activity_main.axml, например:

<FrameLayout
    android:id="@+id/navigation_frame"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_marginLeft="-64dp"
    android:layout_gravity="left|start" />
person Robbit    schedule 15.01.2018
comment
все та же проблема + фон изображения деформируется... когда есть ImageView и изображение centerCrop в порядке.. - person pnk; 15.01.2018
comment
Вы используете DrawerLayout? - person Robbit; 15.01.2018
comment
Не могли бы вы дать мне демо, которое может воспроизвести вашу проблему? Спасибо!!! - person Robbit; 15.01.2018
comment
Поменяй RelativeLayout на FrameLayout, можешь попробовать. - person Robbit; 15.01.2018
comment
хорошо, это работает хорошо .... но все же возможно сделать NavigationView шириной экрана 100%? а не как 80%? - person pnk; 15.01.2018
comment
Хорошо, я проверю это и оставлю вам сообщение позже. - person Robbit; 15.01.2018
comment
Это работает, когда я сделал это - person pnk; 15.01.2018