2017-02-15 4 views
0

J'ai mis en place un bouton d'action flottante dans mes mises en page. Le problème est quand j'ai trop de données dans ma disposition, le bouton ne reste pas dans la même position, il défile vers le bas de la mise en page. J'ai besoin de la même boîte de réception Gmail: un bouton flottant qui est toujours accessible, peu importe les données.Floating Action Bouton faire défiler avec le contenu

Ceci est mon code pour afficher le bouton

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

    <include 
     android:id="@+id/frgOffline" 
     android:visibility="gone" 
     layout="@layout/frg_offline"/> 


    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" card_view:cardBackgroundColor="@android:color/white" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginRight="5dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginBottom="7dp" 
     android:layout_marginTop="7dp" 
     android:gravity="center_vertical|left"> 

      <LinearLayout 
       android:visibility="gone" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center_horizontal" 
       android:orientation="vertical"> 

       <TextView 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:layout_marginTop="25dp" 
        android:textAppearance="?android:attr/textAppearanceSmall" 
        android:text="text" 
        android:layout_marginBottom="15dp" 
        android:textStyle="bold"/> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:padding="15dp" 
        android:layout_margin="5dp" 
        android:textAppearance="?android:attr/textAppearanceSmall"/> 

       <com.exampleapp.expandiblelist 
        android:id="@+id/expListaResultado" 
        android:groupIndicator="@null" 
        android:layout_height="fill_parent" 
        android:transcriptMode="disabled" 
        android:layout_width="match_parent"/> 
      </LinearLayout> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/btnNueva" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:elevation="4dp" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="5dp" 
      android:src="@drawable/ic_nuevo" 
      android:layout_gravity="bottom|right" 
      app:backgroundTint="@color/blue"/> 

     </android.support.v7.widget.CardView> 
</LinearLayout> 

Que se passe-t-il?

Merci de votre aide!

+0

http://stackoverflow.com/questions/35338316/how-to-set-the-fixed-position-for-floating-action-button-above-very-long-listvie –

Répondre

0

Vous pouvez voir ce code cela fonctionnera bien avec vous

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

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" card_view:cardBackgroundColor="@android:color/white" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginRight="5dp" 
    android:layout_marginLeft="5dp" 
    android:layout_marginBottom="7dp" 
    android:layout_marginTop="7dp" 
    android:gravity="center_vertical|left"> 

    <LinearLayout 
     android:visibility="gone" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center_horizontal" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_marginTop="25dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="text" 
      android:layout_marginBottom="15dp" 
      android:textStyle="bold"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="15dp" 
      android:layout_margin="5dp" 
      android:textAppearance="?android:attr/textAppearanceSmall"/> 

     <com.exampleapp.expandiblelist 
      android:id="@+id/expListaResultado" 
      android:groupIndicator="@null" 
      android:layout_height="fill_parent" 
      android:transcriptMode="disabled" 
      android:layout_width="match_parent"/> 
    </LinearLayout> 



</android.support.v7.widget.CardView> 
<android.support.design.widget.FloatingActionButton 
    android:id="@+id/btnNueva" 
    android:layout_width="48dp" 
    android:layout_height="48dp" 
    android:elevation="4dp" 
    android:layout_marginBottom="16dp" 
    android:layout_marginLeft="5dp" 
    android:src="@mipmap/ic_launcher" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="16dp" 
    /> 
</RelativeLayout> 
0

dont vous avez besoin coordinatorlayout pour cette essayer celui-ci, il pourrait aider

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="info.androidhive.fab.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" /> 

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

dans la mise en page content_main mettre tout votre code nécessaire ..