[英]FloatingActionButton inside constraintLayout in ScrollView
i have a floatingActionButton inside a ConstraintLayout which is inside a ScrollView我在 ScrollView 内的 ConstraintLayout 中有一个 floatingActionButton
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_grey">
<androidx.constraintlayout.widget.ConstraintLayout>
----
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bag_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
/>
-----
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
the problem is that the button is scrolling down and up with the UI问题是按钮随着用户界面向下和向上滚动
Ps: i don't know if it is important, but the scrollView is inside a drawerLayout ps:不知道重要不重要,但是scrollView在drawerLayout里面
You can make Your root view as FrameLayout then inside it, you will but the ScrollView then the FAB button something like below您可以将您的根视图设置为FrameLayout然后在其中,您将使用ScrollView然后是FAB按钮,如下所示
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_grey">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_grey">
<androidx.constraintlayout.widget.ConstraintLayout>
<!-- your view xml here -->
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@drawable/bag_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
/>
</FrameLayout>
To place the floating action button, use CoordinatorLayout
.要放置浮动操作按钮,请使用CoordinatorLayout
。 A CoordinatorLayout
helps facilitate interactions between views contained within it, which will be useful to describe how to animate the button depending on scroll changes. CoordinatorLayout
有助于促进其中包含的视图之间的交互,这对于描述如何根据滚动更改为按钮设置动画很有用。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:layout_margin="16dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.