2016-05-23 27 views
0

i FloatingActionButton oben auf der Ansicht zu verankern will,
und dies ist mein Code:FloatingActionButton Anker auf einen Blick

<?xml version="1.0" encoding="utf-8"?> 
<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" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".ui.activity.MainActivity"> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/coordinator" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <com.alirezaafkar.toolbar.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:direction="rtl" 
       app:navigationIcon="@drawable/ic_arrow_back_white_24dp" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:title="@string/app_name"> 

       <TextView 
        android:id="@+id/tv_toolbar_title" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:layout_gravity="center" 
        android:gravity="center" 
        android:textColor="@android:color/white" 
        android:textSize="20dp" 
        android:textStyle="bold" /> 

      </com.alirezaafkar.toolbar.Toolbar> 

     </android.support.design.widget.AppBarLayout> 

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

      <FrameLayout 
       android:id="@+id/container_body" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     </FrameLayout> 

     <ViewSwitcher 
      android:id="@+id/viewSwitcherBottomBar" 
      android:layout_width="wrap_content" 
      android:layout_height="120dp" 
      android:layout_gravity="bottom" 
      android:inAnimation="@android:anim/slide_in_left"> 

      <include layout="@layout/bottom_bar_dest" /> 

      <include layout="@layout/bottom_bar_request" /> 


     </ViewSwitcher> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab_my_location" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end|bottom" 
      android:layout_margin="16dp" 
      android:layout_marginBottom="60dp" 
      android:paddingBottom="60dp" 
      android:src="@drawable/ic_my_location_white_24dp" 
      app:borderWidth="0dp" 
      app:elevation="6dp" 
      app:fabSize="mini" 
      app:layout_anchor="@id/viewSwitcherBottomBar" 
      app:layout_anchorGravity="top|right" /> 


    </android.support.design.widget.CoordinatorLayout> 


und das ist das Ergebnis,
aber das Ergebnis ist nicht genau an der Spitze der Ansicht:

enter image description here


wie kann ich EXA bringen floatingActionButton ganz oben auf der Aussicht?
bearbeiten:
Ich möchte das FloatingActionButton keine Überlappung mit verankerte Ansicht haben.

+0

Sie bedeutet nach Symbolleiste oder vor Toolbar? – sushildlh

+0

@sushildlh, ich meine die grüne floatbutton, die auf der anderen Ansicht am unteren Rand des Bildschirms ist – ReZa

Antwort

1

statt Polsterung und Marge auf FloatingActionButton geben, stelle ich die Polsterung in der Ansicht und es funktioniert:

<ViewSwitcher 
     android:id="@+id/viewSwitcherBottomBar" 
     android:layout_width="wrap_content" 
     android:layout_height="120dp" 
     android:paddingTop="25dp" 
     android:layout_gravity="bottom" 
     android:inAnimation="@android:anim/slide_in_left"> 

     <include layout="@layout/bottom_bar_dest" /> 

     <include layout="@layout/bottom_bar_request" /> 

    </ViewSwitcher> 


<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab_my_location" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="16dp" 
    android:src="@drawable/ic_my_location_white_24dp" 
    app:borderWidth="0dp" 
    app:elevation="6dp" 
    app:fabSize="mini" 
    app:layout_anchor="@id/viewSwitcherBottomBar" 
    app:layout_anchorGravity="top|right" />