2015-12-07 11 views
13

私はそれがのLinearLayoutで影を働き、キャストこのCoordinatorLayoutとAppBarLayout標高

<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> 

のようなアプリケーションバーのレイアウトを作成しました:

<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> 

は、しかし、私はCoordinatorLayoutの影にそれを置くときであります行った:

<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> 

私はどのようにして再度影を表示することができますか?デフォルトでは、それは -

CollapsingToolbarLayoutが非固定の要素を示しているとき標高を削除
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); 
} 

source codeに見られるよう

enter image description here

答えて

10

これは、実際にCollapsingToolbarLayoutの実装の詳細ですピン止めされた子のみが表示されている場合にのみ標高があります。

+9

この問題を解決する方法 –

+1

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

+0

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

1

理由は上記で、これが解決しよう:

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

ありがとう、それは私のために働いた。 :) –

関連する問題