gpt4 book ai didi

android - ToolBar 和 CollapsingToolBar 之间的主要区别

转载 作者:行者123 更新时间:2023-11-29 00:05:34 25 4
gpt4 key购买 nike

Android 中的ToolBar 和CollapsingToolBar 有什么区别?我试着在网上找到它,但找不到任何有用的资源

最佳答案

工具栏看起来像这样:

enter image description here

您可以将它移动到屏幕上任何您想要的位置。它就像一个 View 一样对待。

让我们看看如何将它与其他 View 放在自己的布局文件中:

<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 是一个包装器,用于在工具栏上执行某种动画并将图像等 View 添加到工具栏。这是一个例子:

enter image description here

当您在折叠工具栏上向下滑动时,它会显示其他 View 。

这是一个代码示例,请注意我是如何将工具栏放在可折叠工具栏内的,它将它包裹起来:

<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>

注意:您可能想将它放在协调器布局中,但我不想增加更多困惑。

关于android - ToolBar 和 CollapsingToolBar 之间的主要区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34046328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com