2015-12-02 68 views
1

android中的ToolBar和CollapsingToolBar有什么区别? 我试着在网上寻找,但没找到什么有用的资源ToolBar和CollapsingToolBar之间的主要区别

+0

CollapsingToolbarLayout是Toolbar的一个包装器,它实现了一个折叠应用程序bar.Naturally一个ToolBar不这样做。这里是一个什么CollapsingToolBar看起来像一个视频 - https://www.youtube.com/watch?v=m83CEd55uIo – Tasos

+0

CollapsingToolBar可以容纳一个工具栏和其他东西 –

回答

2

工具栏是这样的:

enter image description here

你可以你想在屏幕上任意位置移动。它的处理就像一个视图。

让我们看看如何可以把它放在自己的布局文件与其他观点:

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

<Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="56dp"> 
</Toolbar> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="@color/gray"/> 

和collapsingtoolbar是做一种动画的工具栏上添加视图类似于包装图像到工具栏。这里有一个例子:

enter image description here

当你向下滑动折叠工具栏上它显示的其他意见。

这里是一个代码示例,并注意我是如何把工具栏可折叠工具栏里面,它包装它:

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:fitsSystemWindows="true"> 

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

     <com.antonioleiva.materializeyourapp.SquareImageView 
      android:id="@+id/image" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scaleType="centerCrop" 
      android:fitsSystemWindows="true" 
      app:layout_collapseMode="parallax"/> 

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

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

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

注意:您可能希望把在协调布局,但我没有”想增加更多的困惑。

相关问题