我在FloatingActionButton
里面有一个ConstraintLayout
,就像这样:
<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类上)使Fragment
上的布局膨胀时,它不会出现。
我试图实现这里提到的解决方案,仍然在ConstraintLayout
:Bottom Align Floating Action Button
如果我用Top和Left约束显示它,看起来很好。
我错过了什么?谢谢!
您的布局包括以下两个约束:
app:layout_constraintRight_toLeftOf="parent" app:layout_constraintBottom_toTopOf="parent"
这将在功能上将FAB的右下角定位在屏幕的左上角。换句话说,您已将FAB限制在屏幕外。
很有可能你意味着你希望FAB的右边位于屏幕的右边,而FAB的底部位于屏幕的底部。所以请改用它们:
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"