2

In meinem Layout habe ich eine FrameLayout, in der ich verschiedene Layouts je nach Benutzereingabe anzeigen möchte. Ich möchte ein FloatingActionButton in all diesen Layouts anzeigen.FAB innerhalb FrameLayout auf Fragmenten zu sein

Um nicht die FloatingActionButton in allen von ihnen zu wiederholen, möchte ich es an die FrameLayout angeschlossen haben. Das Problem ist, dass die Schaltfläche oben auf dem fragment Layout nicht korrekt angezeigt wird. Zum Beispiel, die ursprüngliche fragment angezeigt, hat eine GridView und die Schaltfläche ist dahinter.

activity_main.xml:

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

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:baselineAligned="false" 
     android:orientation="horizontal" 
     android:weightSum="4"> 

     <LinearLayout 
      android:id="@+id/categories_layout" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:paddingRight="20dp"> 

      <ExpandableListView 
       android:id="@+id/categories_listView" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
     </LinearLayout> 

     <FrameLayout 
      android:id="@+id/mainPane" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="3"> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/settings" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom|start" 
       android:layout_margin="8dp" 
       android:clickable="true" 
       android:elevation="5dp" 
       android:src="@android:drawable/ic_menu_search" /> 
     </FrameLayout> 
    </LinearLayout> 
</LinearLayout> 

und das fragment Layout angezeigt programmatisch:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="xeniasis.mymarket.MainActivity"> 

     <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/swipeRefreshContainer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:paddingBottom="@dimen/activity_vertical_margin" 
      android:paddingLeft="8dp" 
      android:paddingRight="8dp" 
      android:paddingTop="@dimen/activity_vertical_margin"> 

      <GridView 
       android:id="@+id/productsGridview" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:numColumns="3"></GridView> 

     </android.support.v4.widget.SwipeRefreshLayout> 
</LinearLayout> 

Das Ergebnis: enter image description here

+0

Sind alle Fragmente auf der gleichen Aktivität? Wenn dies der Fall ist, können Sie es im Aktivitätslayout hinzufügen, sodass es immer über dem FrameLayout bleibt. – Francesc

+0

Ja, sie sind alle in MainActivity und das ist es Layout – XeniaSis

+0

Wo sind Sie das Fragment aufblasen? in der 'FrameLayout'' mainPane'? – Uday

Antwort

4

In der FrameLayout, eine weitere Framelayout deklarieren und das Fragment dort aufblasen. Es sollte funktionieren.

... <LinearLayout> 
    ..... 

    <FrameLayout 
     android:id="@+id/mainPane" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="3"> 

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


     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/settings" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|start" 
      android:layout_margin="8dp" 
      android:clickable="true" 
      android:elevation="5dp" 
      android:src="@android:drawable/ic_menu_search" /> 
    </FrameLayout> 
+0

danke! dieser hat das Problem behoben :) – XeniaSis

0

ändert es so, so dass der FAB und das Fragment don Teilen Sie nicht das gleiche FrameLayout:

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

    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar" /> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:baselineAligned="false" 
     android:orientation="horizontal" 
     android:weightSum="4"> 

     <LinearLayout 
      android:id="@+id/categories_layout" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:paddingRight="20dp"> 

      <ExpandableListView 
       android:id="@+id/categories_listView" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
     </LinearLayout> 

     <FrameLayout 
      android:id="@+id/mainPane" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="3"/> 

    </LinearLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/settings" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|start" 
     android:layout_margin="8dp" 
     android:clickable="true" 
     android:elevation="5dp" 
     android:src="@android:drawable/ic_menu_search" /> 

    </FrameLayout> 
</LinearLayout> 
+0

platziert das den FAB in der unteren linken Ecke des Bildschirms. Ich wollte es in der unteren linken Ecke des 'FrameLayout', das nur 3/4 des Bildschirms ist – XeniaSis

0

hinzufügen FAB in der framelayout ohne coordinativelayout

mit
<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/framelayout" 
     android:layout_below="@+id/drawer_toolbar" 
     android:layout_above="@+id/drawer_foot" > 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/shareFab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|right" 
      android:layout_margin="8dp" 
      android:clickable="true" 
      android:elevation="5dp" 
      android:src="@android:drawable/ic_menu_share" /> 
    </FrameLayout>