1

J'ai quelques problèmes avec FloatingActionButton, il fonctionne comme vous le souhaitez sur l'émulateur, mais quand j'installer sur mon téléphone (Galaxy s4, Android V4.4.4) il ne fonctionne pas comme on le souhaite, je joins une des images pour illustrer le bug. Quelqu'un peut-il me dire ce que je peux faire?FloatingActionButton ne fonctionne pas correctement

Je mets la vue dans un fragment

Fragment classe

public class MiniGameMenuFragment extends Fragment implements View.OnClickListener { 
    protected FloatingActionButton more_menu_btn, card_view_mode_btn, expand_view_btn; 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.mini_menu_fragment, container, false); 
     this.more_menu_btn = (FloatingActionButton) view.findViewById(R.id.more_c_btn); 
     this.card_view_mode_btn = (FloatingActionButton) view.findViewById(R.id.card_view_mode_c_btn); 
     this.expand_view_btn = (FloatingActionButton) view.findViewById(R.id.expand_view_c_btn); 

     this.more_menu_btn.setOnClickListener(this); 
     this.card_view_mode_btn.setOnClickListener(this); 
     this.expand_view_btn.setOnClickListener(this); 

     return view; 
    } 


    @Override 
    public void onClick(View v) { 

    } 

} 

mini_menu_fragment.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@color/red"> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/more_c_btn" 
      android:layout_width="38dp" 
      android:layout_height="38dp" 
      android:clickable="true" 
      android:scaleType="center" 
      android:src="@mipmap/ic_more_vert_white_24dp" 
      app:backgroundTint="#ff9800" 
      app:borderWidth="0dp" 
      app:elevation="8dp" 
      app:fabSize="normal" 
      app:pressedTranslationZ="12dp" 
      app:rippleColor="#ff5722" /> 
    </LinearLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/card_view_mode_c_btn" 
     android:layout_width="38dp" 
     android:layout_height="38dp" 
     android:clickable="true" 
     android:src="@mipmap/card_expanded_view_mode" 
     app:backgroundTint="#ff9800" 
     app:borderWidth="0dp" 
     app:elevation="8dp" 
     app:pressedTranslationZ="12dp" 
     app:rippleColor="#ff5722" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/expand_view_c_btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="24dp" 
     android:clickable="true" 
     android:src="@mipmap/zoom_out_white" 
     app:backgroundTint="#ff9800" 
     app:borderWidth="0dp" 
     app:elevation="8dp" 
     app:fabSize="normal" 
     app:pressedTranslationZ="12dp" 
     app:rippleColor="#ff5722" /> 
</LinearLayout> 

activité principale xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/gameBackground" 
    android:orientation="vertical" 
    tools:context="com.example.MainActivity"> 


    <RelativeLayout 
     android:id="@+id/floating_menu_container_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true"> 

    </RelativeLayout> 

</RelativeLayout> 

MainActivity classe

public class MainActivity extends AppCompatActivity { 
    FragmentManager fragmentManager; 
    FragmentTransaction transaction; 

    MiniGameMenuFragment miniGameMenu; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     this.miniGameMenu = new MiniGameMenuFragment(); 

     this.fragmentManager = getFragmentManager(); 
     this.transaction = fragmentManager.beginTransaction(); 

     this.transaction.add(R.id.floating_menu_container_layout, miniGameMenu, "miniGameMenuFragment"); 
     this.transaction.commit(); 
    } 

    @Override 
    protected void onResumeFragments() { 
     super.onResumeFragments(); 
    } 
} 

Sur Emulator

enter image description here

Le téléphone Galaxy 4s

enter image description here

SOLVED:

Le problème était le élévation, comme @SadiqMdAsif dit 8DP était trop pour ma galaxie de thats résolution pourquoi il a créé une marge supplémentaire pour que je réduit à 2DP

+0

La résolution n'est pas même dans les deux appareils. Vous devriez avoir une disposition séparée pour différentes tailles d'écran. –

+0

@SadiqMdAsif alors comment puis-je le réparer? marge négative? comme vous pouvez voir la marge n'est pas le problème – kobbycoder

+0

voir ma réponse ci-dessous pour créer de multiples variations de disposition. vous définissez 'DP' qui signifie 'pixel d'affichage' dans un appareil basse résolution, ils ont moins de pixels que le pixel haut. donc 10DP prendra plus d'espace dans le dispositif de résolution inférieure. –

Répondre

1

Créer une variation de cette option dans la page concepteur

enter image description here

+0

et comment mon application saura quand passer? dois-je le faire par programme? ou il le fait automatiquement, je l'ai déjà créé maintenant – kobbycoder

+0

va automatiquement passer d'un modèle en fonction de la taille –

+0

j'ai ajouté de petite taille mais toujours le même Ma question est l'espacement entre les boutons pas la taille du bouton – kobbycoder

0

Essayez d'utiliser la mise en page relative ou la mise en forme du cadre au lieu de la mise en page linéaire.