繁体   English   中英

底栏顶部的浮动操作按钮

[英]Floating action button in top of Bottom Bar

如何在底栏/导航底部视图的顶部有浮动操作按钮,如图中所示! 请帮我 !

AnchorImage

您需要使用FloatingActionButton的高程属性。

elevation =“8dp”为我工作。

样本布局:

<FrameLayout 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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <TextView
            android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:text="@string/title_home" />

    </FrameLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/navigation" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:layout_marginBottom="40dp"
        android:clickable="true"
        app:elevation="8dp"
        app:srcCompat="@android:drawable/ic_input_add" />

</FrameLayout>

底部栏是他们在他们的应用程序中创建的东西。 它不是android本身的功能(Home / Back / App)按钮。

因此,与任何视图一样,将视图放在彼此之上就更容易了。

这可以通过相对布局来完成

另外需要注意的是,通过android studio,其中一个android活动模板实际上创建了一个类似于图片中所示的悬停按钮的示例。 使用向导创建活动,然后根据需要移动按钮。

在此输入图像描述

您可以在xml中使用FloatingActionButton属性。

设置FloatingActionButton layout_anchor(要附加的视图ID)和layout_anchorGravity。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM