我想对齐我的 FAB 的右下角。
- 我试过
android:gravity="bottom|right"
- 当我尝试
android:layout_alignParentBottom="true
"FAB
消失 - 当我尝试
android:layout_alignBottom="@id/lista_tiendas"
FAB
消失
看起来并不复杂,但我就是做不到
有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lista_tiendas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:divider="@android:color/transparent"
android:dividerHeight="4.0sp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_48dp"
app:backgroundTint="@color/spg_rosa"
app:borderWidth="0dp"
app:elevation="8dp"
app:fabSize="normal"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="@id/lista_tiendas"
/>
</RelativeLayout>
最佳答案
对于RelativeLayout
:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
... />
对于CoordinatorLayout
,你应该使用android:layout_gravity="end|bottom"
对于ConstraintLayout
:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
... />
见 this answer了解更多信息。
关于android - 底部对齐 float 操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30769080/