FloatingActionButton 的右侧和底部约束使其不可见

Right and Bottom Constraint on FloatingActionButton makes it unseen

我在 ConstraintLayout 里面有一个 FloatingActionButton,像这样:

<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab_add_topic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/ic_add"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintBottom_toTopOf="parent"
                android:foregroundGravity="right|bottom"
                android:layout_marginRight="@dimen/material_tooltip_margin_top"
                android:layout_marginBottom="@dimen/material_tooltip_margin_top"
                android:elevation="6dp"
                app:pressedTranslationZ="12dp"
                app:borderWidth="0dp"/>

</android.support.constraint.ConstraintLayout>

但是,当我使用 Android 数据绑定(在 Kotlin class 上)在 Fragment 上扩充布局时,它不会出现。

我试图实施此处提到的解决方案,仍在 ConstraintLayout 内:

如果我用顶部和左侧约束显示它,它看起来很好。

我错过了什么吗?谢谢!

您的布局包括以下两个约束:

app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintBottom_toTopOf="parent"

这会在功能上将 FAB 的右下角定位在屏幕的左上角。换句话说,您已将 FAB 限制在屏幕外。

很可能您的意思是您希望 FAB 的右侧位于屏幕的右侧,而 FAB 的底部位于[=19] =]屏幕底部。所以改用这些:

app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"

FloatingActionButton可以对齐父级的所有角ConstraintLayout:

FAB constraint relation XML markup
top & start app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
top & end app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
bottom & start app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
bottom & end app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"

要均匀放置它,请使用 layout_margin:

android:layout_margin="24dp"