我怎样才能使这个 TextView 位于 FloatingActionButton 之上?

How can I make this TextView above the FloatingActionButton?

我想使此文本视图在 FloatinActionButton 上方可见,但我尝试过的解决方案均无效,还有其他建议吗? 谢谢。

[Android工作室截图][1] [1]: https://i.stack.imgur.com/oYBWF.png

首先您需要使用 Extended FAB 而不是 FAB。好的,让我们开始吧:

步骤 1

将此添加到您的 build.gradle (moudle) 文件

implementation 'com.google.android.material:material:1.1.0'

dependencies

步骤 2

Extended FAB 形状将是矩形,因此您应该创建一个可绘制资源文件并将其命名为 shape.xml 并在其中添加以下代码:

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<size
android:height="50dp"
android:width="50dp"/>
<solid android:color="@color/colorPrimary" />
</shape>

步骤 3

现在,让我们创建 Extended FAB,它将是这样的:

   <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/shape"
    android:text="OK"/>

结果:

很简单。只需将其放入您的文本视图

   android:elevation="1dp"

这会给它一个高度。