底部导航栏顶部的浮动操作按钮

9
如何在底部导航栏/底部视图上方添加浮动操作按钮,就像图片中所示!请帮助我!

AnchorImage

3个回答

16

你需要使用FloatingActionButton的elevation属性。

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>

成功了!我们如何更改底部视图元素之间的间距,就像图片中显示的那样? - Mukund Srivathsan
1
不幸的是,除非您覆盖原始类,否则没有太多的余地来做到这一点,但是要使其看起来像图像,如果您仔细观察,有5个元素,中间一个是空格。这将起到作用。希望能有所帮助 :) - Abu Faisal
有没有办法可以增加底部栏图标的大小!无论图标尺寸如何,它始终保持相同的大小! - Mukund Srivathsan
如果我的回答有用,请接受并根据需要创建新问题。 - Abu Faisal

1
那个底部栏是他们在应用中创建的。它不是Android本身的功能按钮(主页/返回/应用)。因此,像任何视图一样,将视图放在彼此之上非常容易。这可以通过相对布局来实现。另一个需要注意的事情是,在Android Studio中,其中一个Android活动模板实际上创建了一个类似于您图片中显示的悬停按钮的示例。使用向导创建活动,然后根据需要移动按钮即可。

enter image description here


有一个底部栏我可以创建!我正在寻求帮助,将浮动操作按钮放置在底部栏的中心图标位置!我无法在任何地方找到它。 - Mukund Srivathsan
如果您的意思是将其提升到最高层,则请参见我上面在Android Studio中展示的示例或者Abu的答案。@MukundSrivathsan - IAmGroot

0

您可以使用XML中的FloatingActionButton属性。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接