2017-07-10 6 views
0

Je suis en train de faire une opération sur le bouton d'action flottante. J'ai une vue de liste et montre la publicité de google au fond de mon écran, le bouton d'action de flottement montre au même endroit (bas | fin). Le bouton d'action cache donc l'annonce.Comment nous pouvons mettre le bouton d'action flottant au-dessus de toute mise en page

Je souhaite déplacer le bouton d'action Floating au-dessus de la disposition linéaire.

S'il vous plaît un coup d'oeil l'image: enter image description here

Mon code ressemble à:

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="@dimen/fab_margin" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 
    android:layout_gravity="bottom|end" 
    android:src="@drawable/fav" 
    android:adjustViewBounds="false" /> 


adLayoutId is ad layout id 

S'il vous plaît aider.

Merci d'avance.

Répondre

1

Vous devez utiliser RelativeLayout, et comme nous le savons, plus tard les enfants dans un RelativeLayout ont tendance à flotter au-dessus des enfants plus tôt dans un RelativeLayout. Donc, pour faire flotter un FAB par n'importe quelle mise en page, assurez-vous que le FAB est défini après toutes les vues (à la fin de la mise en page XML).

Si vous utilisez android:layout_margin="@dimen/fab_margin" la meilleure façon de manipuler FAB est définir des dépendances entre les vues, par exemple:

<?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"> 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/adLayoutId"/> 

    <LinearLayout 
     android:id="@+id/adLayoutId" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:background="@android:color/black"/> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/adLayoutId" 
     android:layout_alignParentRight="true" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/fav"/> 
</RelativeLayout> 

bouton d'action flottante sera toujours au-dessus de l'annonce mise en page linéaire et indépendante de la taille de mise en page d'annonce. J'espère que ça aide.

+0

Merci, ça fonctionne comme un charme .... – itin

0

Ajouter une marge inférieure de 55dp qui est la taille des bannières AdMob

Cette ligne soit le bouton flottant ou entourant la mise en page.

android:layout_marginBottom="55dp

0
<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_marginBottom="100dp" 
     android:layout_marginRight="30dp" 
     /> 
+0

Cela va certainement résoudre votre problème. – Saint