2016-01-18 100 views
13

我想才达到如下的布局:透明AppBarLayout和CollapsingToolbarLayout

  1. 地图作为基础布局上述
  2. 透明窗CollapsingToolbarLayout
  3. RecyclerView内部内容

我包括这应该看起来像一个例子。

enter image description here

我从下面为Cheesesquare的CollapsingToolbarLayout和AppBarLayout实现这个伟大的例子。我设法使用CollapsingToolbarLayout中的地图处理内容(在布局xml中注释掉),但这不是所期望的结果。

但是,我没有找到任何解决方案/文档,使灰色框(见中间的内部图像)在初始位置是透明的。我希望它透明以便透视地图。当用户向上滚动时,CollapsingToolbarLoyoyut应该完成工作并折叠透明窗口并显示工具栏。现在图像看起来只是白色或我给它的任何颜色。我已经尝试将颜色设置为透明,但没有达到预期的效果。

所以我的问题如何在初始阶段设置“CollapsingToolbarLayout”透明(请参阅图像第1层灰色框)?

这是我的布局代码。 CollapsingToolbarLayout的效果很好,但我看不到下面的地图。如果有可能实施将会很好。

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


    <!-- Layer 0 --> 
    <FrameLayout 
     android:id="@+id/overlayFragmentMap" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:elevation="0dip" 
     /> 


    <!-- Layer 1 --> 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="192dp" 
     android:fitsSystemWindows="true" 
     android:theme="@style/CustomActionBar"> 
     <!--android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar--> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorAccent" 
      app:expandedTitleMarginBottom="32dp" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:expandedTitleTextAppearance="@color/black" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 


      <!-- Map view inside here works perfectly but is not 
      the deisired result --> 
      <!-- 
      <FrameLayout 
       android:id="@+id/overlayFragmentMap" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:elevation="0dip" 
       app:layout_collapseMode="parallax" 
       /> 
      --> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@drawable/transparent" 
       android:elevation="4dip" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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




    <!-- Fragment with recyclerview inside --> 
    <FrameLayout 
     android:id="@+id/overlayFragmentContent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:elevation="3dip" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dip" 
     android:clickable="true" 
     app:layout_anchor="@+id/appbar" 
     app:layout_anchorGravity="bottom|right|end" /> 

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

该透明窗口的内容是什么?或者它只是一个透明的窗口? – Mohsen

+1

应该只是一个透明的视图。我希望看到底层的地图。 – Devdroid

回答

26

我怎么能设置 “CollapsingToolbarLayout” 透明的 初始阶段(见图像层1个灰色框)?

尝试在你的AppBarLayout使用:android:background="@android:color/transparent"

<android.support.design.widget.AppBarLayout 
      android:id="@+id/appbar" 
      android:layout_width="match_parent" 
      android:layout_height="192dp" 
      android:background="@android:color/transparent" 
      android:fitsSystemWindows="true"> 

下面是结果:

enter image description here

希望有所帮助。

+0

现在完美地工作,谢谢你的回答:-) – Devdroid

+0

Yw,很高兴听到那个.goodluck – Mohsen

相关问题