android - 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>
解决方案
您只需要删除xml 中的行:
app:layout_constraintStart_toStartOf="parent"
然后有了利润,你就可以走了。
推荐阅读
- c++ - Visual C:模板类中的自定义错误消息
- haskell - 为什么在代数数据类型中可以将乘积之和视为范式?
- c# - 用户控件中的自定义依赖属性不绑定
- r - 如何从列中提取变量
- angular - 如何将对象从服务传递到Angular8中的组件?
- apache-spark - 如何调试为什么挂起阶段处于未知状态?
- c# - 如何避免每次测试重复的 TestFixtures 安排?
- wpf - 如何将 1 个日历控件绑定到另一个日历控件?例如,如果我在 1 个日历中进行了更改,它将反映在 wpf 中的另一个日历中
- python - ctypes 对函数中可变参数的奇怪处理
- javascript - 如何使用 ng-model 用值预填充文本框