首页 > 解决方案 > floatingActionButton 如何位于屏幕右下角

问题描述

我正在尝试在我的应用程序的右下角设置 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>

标签: androidfloating-action-button

解决方案


您只需要删除xml 中的行:

app:layout_constraintStart_toStartOf="parent"

然后有了利润,你就可以走了。


推荐阅读