2017-07-28 2 views
0

Je voudrais savoir pourquoi cette barre d'outils a jeté une ombre que si NestedScrollView est là (j'ai cet exemple de l'Internet)Android: élévation de la barre d'outils/Shadow

<android.support.design.widget.CoordinatorLayout 
    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.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <!-- Your scrolling content --> 

    </android.support.v4.widget.NestedScrollView> 

    <android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:local="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      local:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      /> 
    </android.support.design.widget.AppBarLayout> 

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

Cette barre d'outils (sans NestedScrollView) ne pas lancer l'ombre:

<android.support.design.widget.CoordinatorLayout 
    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.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:local="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      local:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      /> 
    </android.support.design.widget.AppBarLayout> 

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

Je peux poster des photos, si nécessaire, mais je n'ai aucune idée pourquoi cela se produise. C'est ce que je l'ai essayé jusqu'à présent:

  • Réglage clipToPadding = "false" sur le parent disposition linéaire
  • élévation Configuration manuelle (mon appareil n'est pas pré-Lollipop)
  • Seting outlineProvider = » les bornes » dans la vue
  • Réglage android: hardwareAccelerated = "true" sur le AndroidManifest.xml

Edit: Je l'ai résolu en utilisant la balise. Vérifiez ma réponse avec le code.

+0

Veuillez envoyer l'image que vous voulez réaliser et ce que vous obtenez avec votre code. Je t'aiderai. –

+1

@AmrishKakadiya Lire ma réponse, j'ai déjà réussi à le réparer, mais je peux poster des photos quand même. Et merci d'offrir votre aide: D –

+0

Super, pas besoin de poster une image. –

Répondre

0

En cherchant un peu plus, j'ai découvert que la balise de fusion ferait l'affaire. Cette balise peut fusionner le toolbar.xml dans la mise en page parente qui prendra en charge la commande z et placer la barre d'outils là où je l'ai voulu.

<merge xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 
<android.support.design.widget.CoordinatorLayout 
    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.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:local="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      local:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      /> 
    </android.support.design.widget.AppBarLayout> 

</android.support.design.widget.CoordinatorLayout> 
</merge> 

Et non, demander ici était pas la première chose que je l'ai fait, il a été un coup de chance de trouver cette balise dans moins d'une heure après que je poste ici. Quoi qu'il en soit, voici ma solution.