【发布时间】:2020-10-11 21:29:05
【问题描述】:
我有一个详细信息片段,其中显示有关所选项目的信息。图像嵌入在CoordinatorLayout 和CollapsingToolbarLayout 中。该行为按预期工作:当图像向下滚动时,FloatingActionButton 与 CollapsingToolbarLayout 的末尾一起向上滚动。然后,当它完全折叠时,FloatingActionButton 消失了。我想要发生的是这个按钮永远不会消失。它固定在工具栏上很好,但是在查看文档和本网站后,我一直无法找到如何使其保持可见。任何提示将不胜感激!
这是我的布局的简化版本:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
app:contentScrim="@color/colorPrimaryDark"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title="@{movie.title}"
app:toolbarId="@+id/toolbar">
<ImageView
android:id="@+id/fragment_details_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/browse_image_content_description"
android:scaleType="centerCrop"
app:largeSize="@{true}"
app:layout_collapseMode="parallax"
app:posterPath="@{movie.posterPath}" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.heiligbasil.movietvdelight.view.DetailsFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/fragment_details_text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@{movie.title}"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:elevation="6dp"
app:borderWidth="0dp"
app:fabSize="mini"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:pressedTranslationZ="10dp"
app:rippleColor="@color/colorPrimary"
app:srcCompat="@drawable/ic_save" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
【问题讨论】:
标签: android floating-action-button android-coordinatorlayout android-collapsingtoolbarlayout