2017-05-08 91 views

回答

4

您需要使用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> 
+0

它工作!我们如何改变底部视图元素之间的空间,比如它在图像中的显示方式? –

+1

不幸的是,除非你重写原始类,否则没有太多的范围,但为了使它看起来像图像,如果仔细观察,有5个元素,中间是空白区域。这会做伎俩。希望有所帮助:) –

+0

有没有什么办法可以增加底部的图标大小!无论图标大小如何,它始终保持相同的尺寸! –

0

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

因此,就像任何观点一样,将意见放在另一个上面是很容易的。

这可以用Relative layout

另一件事来完成需要注意的,是通过机器人工作室的机器人活动模板一个实际创建类似于您的图片显示的悬停按钮的例子。使用向导创建活动,然后根据需要移动按钮。

enter image description here

+0

我可以创建一个底部栏!我正在寻求帮助来放置浮动动作按钮,就像底部酒吧的中心图标一样!我无法在任何地方找到 –

+0

@MukundSrivathsan如果你的意思是把它提升到一切之上,那么看看我上面显示的android studio中的例子,或者Abu的答案。 – Doomsknight

0

您可以使用FloatingActionButton在XML属性。

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

相关问题