【问题标题】:How can floatingActionButton be located at the right bottom in the screenfloatingActionButton 如何位于屏幕右下角
【发布时间】: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


【解决方案1】:

您只需删除 xml 中的行:

app:layout_constraintStart_toStartOf="parent"

那么有了利润,你就可以走了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-02
    • 2013-02-17
    • 2020-11-05
    • 1970-01-01
    • 2013-04-22
    • 2019-09-04
    • 2019-01-05
    • 2011-01-28
    相关资源
    最近更新 更多