2017-02-03 2 views
0

Je souhaite définir une image comme arrière-plan de ma barre d'outils, avec l'image mise à l'échelle. Pour une raison quelconque, l'image s'affiche juste en dessous de la barre d'outils. et je ne suis pas sûr pourquoi. Toute aide serait grandement appréciée. J'ai essayé plusieurs des façons dont les gens ont suggéré en ligne et aucun d'entre eux ne donne le résultat que je recherche.Xamarin Android - Définir l'arrière-plan de la barre d'outils comme une image, ne fonctionne pas comme prévu

Également: La définition de l'arrière-plan par programme a le même résultat.

Voici mon code de la vue avec l'arrière-plan défini sur l'image

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/main_nav_drawer_layout" 
    android:fitsSystemWindows="true"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/main_nav_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?attr/actionBarSize" 
      android:background="@drawable/header_bg" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
     <FrameLayout 
      android:id="@+id/app_fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 
    <android.support.design.widget.NavigationView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:id="@+id/main_nav_view" 
     android:background="#D3D2D2" 
     app:itemBackground="@drawable/style_menu_bg_color" 
     app:menu="@menu/main_menu" 
     app:headerLayout="@layout/main_menu_header" 
     app:itemTextColor="@drawable/style_menu_text_color" 
     app:itemIconTint="@drawable/style_menu_text_color" /> 
</android.support.v4.widget.DrawerLayout> 

J'ai aussi essayé de cette façon avec un ImageView dans la ToolBar

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/main_nav_drawer_layout" 
    android:fitsSystemWindows="true"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/main_nav_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:src="@drawable/header_bg"/> 
     </android.support.v7.widget.Toolbar> 
     <FrameLayout 
      android:id="@+id/app_fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 
    <android.support.design.widget.NavigationView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:id="@+id/main_nav_view" 
     android:background="#D3D2D2" 
     app:itemBackground="@drawable/style_menu_bg_color" 
     app:menu="@menu/main_menu" 
     app:headerLayout="@layout/main_menu_header" 
     app:itemTextColor="@drawable/style_menu_text_color" 
     app:itemIconTint="@drawable/style_menu_text_color" /> 
</android.support.v4.widget.DrawerLayout> 

enter image description here

Répondre

0

J'étais capable de comprendre et de travailler pour mon scénario. J'ai ajouté une mise en page relative, avec une vue d'image au-dessus de la barre d'outils (dans le code, pas la position réelle de l'écran), puis j'ai rendu l'arrière-plan transparent et mis à l'échelle.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/main_nav_drawer_layout" 
    android:fitsSystemWindows="true"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <ImageView 
       android:id="@+id/imageViewplaces" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:adjustViewBounds="true" 
       android:src="@drawable/header_bg" 
       android:maxHeight="?attr/actionBarSize" 
       android:scaleType="fitXY" /> 
      <android.support.v7.widget.Toolbar 
       android:id="@+id/main_nav_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:minHeight="?attr/actionBarSize" 
       android:background="#00FFFFFF" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
     </RelativeLayout> 
     <FrameLayout 
      android:id="@+id/app_fragment_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </LinearLayout> 
    <android.support.design.widget.NavigationView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:id="@+id/main_nav_view" 
     android:background="#D3D2D2" 
     app:itemBackground="@drawable/style_menu_bg_color" 
     app:menu="@menu/main_menu" 
     app:headerLayout="@layout/main_menu_header" 
     app:itemTextColor="@drawable/style_menu_text_color" 
     app:itemIconTint="@drawable/style_menu_text_color" /> 
</android.support.v4.widget.DrawerLayout> 

enter image description here