我已经创建了这样的AppBar布局
它工作并在LinearLayout中投射阴影:
但是,当我把它放入CoordinatorLayout时,阴影消失了:
如何让appbar再次展示它的影子?
这实际上是一个实现细节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); }
在CollapsingToolbarLayout
显示非固定元素时删除高程- 默认情况下,只有固定子项可见时才会有高程.
原因如上,请尝试解决:
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { //some other code here ViewCompat.setElevation(appBarLayout, The Elevation In Px); } });