2017-05-08 86 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。

相關問題