1

我试图在抽出时将导航抽屉上的阴影投射到工具栏上,同时还允许将阴影投射到其余的布局。如何在使用CoordinatorLayout时删除导航抽屉在工具栏上投下的阴影

我知道我可以通过在父视图中包装DrawerLayout并在该父视图中添加工具栏来删除阴影,但通过这样做,我无法使滚动布局时工具栏滚动屏幕,因此这不是对我来说可行的解决方案。

我可能会使用AppBarLayout的偏移侦听器以编程方式将工具栏从屏幕上退出,但纯粹的XML解决方案可能是最好的。

我使用这个布局:

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".MainActivity" 
    > 


    <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:clipChildren="true" 
     > 

      <android.support.design.widget.AppBarLayout 
      app:layout_scrollFlags="scroll" 
      android:id="@+id/profile_screen_appBar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:fitsSystemWindows="true" 
      android:minHeight="150dp"    
      > 

      <android.support.design.widget.CollapsingToolbarLayout 
       app:layout_collapseMode="parallax" 
       app:layout_collapseParallaxMultiplier="0.7" 
       app:layout_scrollFlags="scroll" 
       android:fitsSystemWindows="true" 
       android:id="@+id/collapsingToolbarCurrentUser" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
          > 

       <android.support.v7.widget.Toolbar 
        android:minHeight="0dp" 
        android:fitsSystemWindows="false" 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
            /> 
</android.support.design.widget.CollapsingToolbarLayout> 

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

<android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/recycler" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      /> 

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

    <fragment 
     android:fitsSystemWindows="true" 
     android:id="@+id/fragment_drawerInTesterActivity" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:layout="@layout/fragment_nav_bar" 
     android:name="Fragment" 
     tools:layout="@layout/fragment_nav_bar"/> 

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

问题一言以蔽之:如何删除由抽屉式导航栏上的工具栏的阴影,同时允许工具栏是一个CoordinatorLayout内滚动视图?

回答

0

This回答对我有帮助。这增加了AppBarLayout:

android:elevation="0dp" 
app:elevation="0dp" 

CoordinatorLayout不上阴影的影响,甚至当你将其更改为LinearLayout中。

相关问题