floatingActionButton如何位于屏幕的右下角
How can floatingActionButton be located at the right bottom in the screen
我正在尝试在我的应用程序的右下角设置 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>
您只需删除您xml中的行:
app:layout_constraintStart_toStartOf="parent"
有了边距就可以开始了。
我正在尝试在我的应用程序的右下角设置 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>
您只需删除您xml中的行:
app:layout_constraintStart_toStartOf="parent"
有了边距就可以开始了。