2020-12-03 Material Design之AppBarLayout

协调布局和AppBarLayout一起使用

  1. ToolBar的scrollFlags:
  • scrollFlag为scroll | enterAlways
<com.google.android.material.appbar.AppBarLayout
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        app:title="协调布局"
        app:layout_scrollFlags="scroll|enterAlways"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:titleTextColor="@android:color/white"
        tools:ignore="MissingConstraints" />
</com.google.android.material.appbar.AppBarLayout>
设为scroll|enterAwlays
  • scrollFlag为scroll
<com.google.android.material.appbar.AppBarLayout
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        app:title="协调布局"
        app:layout_scrollFlags="scroll"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:titleTextColor="@android:color/white"
        tools:ignore="MissingConstraints" />
</com.google.android.material.appbar.AppBarLayout>
设为scroll
  • scrollFlag为scroll|enterAlways|snap,根据拉伸距离决定ToolBar的拉伸和隐藏
<com.google.android.material.appbar.AppBarLayout
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="wrap_content">
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        app:title="协调布局"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        android:layout_height="?actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        tools:ignore="MissingConstraints" />
</com.google.android.material.appbar.AppBarLayout>

snap
  • scrollFlag为enterAlwaysCollapsed,注意scroll及enterAlways,需要设置minHeight
<com.google.android.material.appbar.AppBarLayout
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        app:title="协调布局"
        app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
        android:layout_height="200dp"
        android:minHeight="50dp"
        android:background="?attr/colorPrimary"
        app:titleTextColor="@android:color/white"
        tools:ignore="MissingConstraints" />
</com.google.android.material.appbar.AppBarLayout>
enterAlwaysCollapsed
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容