2017-05-19 15 views
0

在我的activity_navigation.xml我把我的FAB放在這裏。下面 的是:如何在所有活動中顯示FAB

<android.support.v4.widget.DrawerLayout 
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" 
xmlns:fab="http://schemas.android.com/apk/res-auto" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/content_frame"> 

    <com.github.clans.fab.FloatingActionMenu 
     android:id="@+id/menu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     fab:menu_icon="@drawable/quick_apply" 
     android:layout_gravity="bottom|right" 
     android:layout_marginBottom="8dp" 
     android:layout_marginRight="8dp"> 

     <com.github.clans.fab.FloatingActionButton 
      android:id="@+id/view_img" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/imgicon" 
      fab:fab_size="mini" 
      fab:fab_label="View Images" /> 

     <com.github.clans.fab.FloatingActionButton 
      android:id="@+id/camera" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/camicon" 
      fab:fab_size="mini" 
      fab:fab_label="Camera" /> 

    </com.github.clans.fab.FloatingActionMenu> 

</FrameLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/navigationView" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:menu="@menu/activity_navigation_drawer" 
    android:background="@color/tableHeader"/> 

我在我的NavigationActivity設置此xml哪裏,這將是像我BaseActivity,然後將其推廣到我的所有其他Activities

我的問題,當運行應用程序FAB不顯示,因爲它已被我分配給content_frame xml覆蓋。但如果我把com.github.clans.fab.FloatingActionMenu放在我的其他activities's xml之一,例如在我的Home Screen中,它會顯示它,但我不知道如何顯示FAB而不重複添加我的xmlFAB的所有行動我把它放在我的NavigationActivity上。

謝謝你的幫助。

更新 通過我使用FrameLayout命名content_frame我的其他activities以顯示Activity喜歡的xml在我Home Screen這樣

FrameLayout contentFrameLayout = (FrameLayout) findViewById(R.id.content_frame); 
    getLayoutInflater().inflate(R.layout.activity_home, contentFrameLayout); 
+0

您的NavigationView具有匹配父級的高度。你框架佈局也高度匹配父母,他們將重疊,你嘗試設置你的框架佈局與20dp高度,並看到 – kggoh

+0

@kggoh它仍然不顯示:(我試圖把20dp layout_height在framelayout。 – natsumiyu

+0

@kggoh我試過把20dp高度放在我現在顯示的晶圓廠的其他活動xml中有沒有辦法解決這個問題?因爲我需要在屏幕上顯示整個活動的內容 – natsumiyu

回答

0

我做什麼是我創建兩個FrameLayoutactivity_navigation.xml

<FrameLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"/> 

<com.github.clans.fab.FloatingActionMenu 
    android:id="@+id/menu" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    fab:menu_icon="@drawable/quick_apply" 
    android:layout_gravity="bottom|right" 
    android:layout_marginBottom="8dp" 
    android:layout_marginRight="8dp"> 

    <com.github.clans.fab.FloatingActionButton 
     android:id="@+id/view_img" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/imgicon" 
     fab:fab_size="mini" 
     fab:fab_label="View Images" /> 

    <com.github.clans.fab.FloatingActionButton 
     android:id="@+id/camera" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/camicon" 
     fab:fab_size="mini" 
     fab:fab_label="Camera" /> 

</com.github.clans.fab.FloatingActionMenu> 

</FrameLayout> 

凡我FAB不是content_frame裏面,所以它不會重疊。

0

的方式//我沒有你資源價值,所以我嘗試做一個測試的例子,用textview替換你的抽屜視圖。如果我把framelayout高度與匹配父項相比,我只能看到一個textview,只有當我把高度設置爲20dp時,它纔會出現兩個textviews。

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="20dp" 
      android:id="@+id/content_frame"> 

      <TextView 
       android:text="text above" 
       android:textSize="20sp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </FrameLayout> 


     <TextView 
      android:text="text below" 
      android:textSize="20sp" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" /> 

    </LinearLayout> 
+0

但它不會顯示佈局在整個屏幕上:( – natsumiyu

+0

)你的意思是什麼,它的線性佈局是匹配父母的高度,也許你必須發佈一個屏幕,你正試圖實現在這裏 – kggoh

0

使用片段即時活動

+0

這應該是在評論,而不是在回答。當你寫一個答案寫相關的代碼片段 – bigbounty

相關問題