底部页面布局上方的浮动按钮

时间:2020-06-29 20:10:14

标签: android

我想设计一个底部面板,该面板具有一个TextView(“删除”)和一个浮动按钮(“ x”),如下所示:

enter image description here

如何实现此目的,以使'x'出现在TextView布局上?我尝试了不同的变体,但它们没有产生我想要的结果。我不确定我缺少什么。我在线上找到许多文章,这些文章在布局上使用FloatingButton,但是由于某些原因,我的输出总是出乎意料。我还发现了关于stackoverflow的类似问题,但答案不是很有帮助:link

我的bottom_sheet.xml布局代码如下:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/delete_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background_primary">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="Delete"
            android:textColor="@color/text_primary"
            android:textSize="15sp" />
    </LinearLayout>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="24dp"
        android:layout_height="24dp"
        app:layout_anchor="@id/delete_container"
        android:layout_gravity="top|end"
        android:src="@drawable/ic_cancel_24dp" />

</FrameLayout>

但这只是将浮动按钮添加到LinearLayout的末尾(右侧)。

我还尝试在我的LinearLayout中添加marginTop,以便它“向下”推送布局,并在按钮的顶部留出空间,但随后该空间仅被白色背景色填充。我还尝试将alpha = 0添加到最外面的FrameLayout来避免这种情况,但是它仍然显示为白色背景。

我将不胜感激。谢谢您的时间。

1 个答案:

答案 0 :(得分:1)

一个带有ConstraintLayout的工作示例(这似乎简单得多):

awk -F, '{printf("%s,%s", $1, $2); for (i=3; i<=NF; i+=3) printf(",%s", $i); printf("\n")}' 
相关问题