【发布时间】:2020-11-24 08:18:11
【问题描述】:
我正在尝试在我的应用程序的右下角设置 floatingActionButton。
我的 Activity.xml 有一个 WebView 和一个带有 ConstraintLayout 的 FloatingActionButton。
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|end"
tools:context=".MainActivity">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_gravity="bottom|end"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:contentDescription="@string/btn_back"
android:src="@drawable/btn_back"
android:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
应该是android:layout_gravity="bottom|right"
-
@Venky , android:layout_gravity="bottom|right" 不起作用。太棒了。
-
如果你有约束布局作为父级,你也不需要那个。只需正确设置约束即可。所以Gooooooood.....
-
@Venky,所以 saaaaaaad。还是不行。
标签: android floating-action-button