2017-05-19 63 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

相关问题