2015-12-07 14 views
13

ich ein AppBar Layout wie dieser es funktioniertCoordinatorLayout und AppBarLayout Höhe

<android.support.design.widget.AppBarLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/appbar_layout" 
    android:layout_height="@dimen/app_bar_height" 
    android:layout_width="match_parent" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:elevation="20dp"> 

    <android.support.design.widget.CollapsingToolbarLayout...> 
</android.support.design.widget.AppBarLayout> 

erstellt haben und wirft einen Schatten in der Linearlayout:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include layout="@layout/app_bar_large" /> 
</LinearLayout> 

Jedoch, wenn ich es in den Schatten CoordinatorLayout gesetzt ist weg:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include layout="@layout/app_bar_large" /> 
</android.support.design.widget.CoordinatorLayout> 

Wie kann ich appbar machen, um seinen Schatten wieder zu zeigen?

enter image description here

Antwort

10

Dies ist tatsächlich eine Implementierung Detail von CollapsingToolbarLayout, wie in der source code gesehen:

if (Math.abs(verticalOffset) == scrollRange) { 
    // If we have some pinned children, and we're offset to only show those views, 
    // we want to be elevate 
    ViewCompat.setElevation(layout, layout.getTargetElevation()); 
} else { 
    // Otherwise, we're inline with the content 
    ViewCompat.setElevation(layout, 0f); 
} 

, die die Erhebung entfernt

wenn die CollapsingToolbarLayout Elemente Nicht-Abonnenten zeigt - standardmäßig ist es Ich habe nur Höhe, wenn nur gepinnte Kinder sichtbar sind.

+9

, wie dieses Problem zu lösen –

+1

http://stackoverflow.com/a/39247130/2158970 – Yuraj

+0

https://stackoverflow.com/a/ 32393698/4542217 –

1

der Grund, oben ist, versuchen Sie, diese zu lösen:

appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 
     @Override 
     public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
      //some other code here 
      ViewCompat.setElevation(appBarLayout, The Elevation In Px); 
     } 
    }); 
+0

Danke, es hat für mich funktioniert. :) –

Verwandte Themen