1

У меня возникли проблемы с FloatingActionButton, он работает по желанию на эмуляторе, но когда я устанавливаю его на свой телефон (Galaxy s4, Android V4.4.4), он не работает по желанию. Я прикрепляю некоторые чтобы проиллюстрировать ошибку. Может кто-нибудь сказать мне, что я могу сделать?FloatingActionButton не работает должным образом

я поставил точку зрения во фрагменте

фрагмента Класса

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> 

Основная активность 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 Class

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(); 
    } 
} 

На эмуляторе

enter image description here

по телефону Galaxy 4s

enter image description here

РЕШИТЬ:

Проблема была высота, как сказал @SadiqMdAsif 8dp было слишком много для Thats разрешения моей галактики s4, почему он создал дополнительный запас, так что я сводится к 2DP

+0

Разрешение не одинаково на обоих устройствах. у вас должна быть отдельная компоновка для разных размеров экрана. –

+0

@SadiqMdAsif, тогда как я могу это исправить? маржа отрицательная? как вы видите, маржа не проблема – kobbycoder

+0

см. мой ответ ниже, чтобы создать несколько вариантов макета. вы устанавливаете «DP», что означает «отображаемый пиксель» в устройстве с низким разрешением, у них меньше пикселей, чем у высокого. поэтому 10DP займет больше места в устройстве с более низким разрешением. –

ответ

1

Создания вариации от этой опции в дизайнерской странице

enter image description here

+0

и как мое приложение будет знать, когда нужно переключаться? я должен делать это программно? или он делает это автоматически, я уже создал его сейчас – kobbycoder

+0

автоматически переключит макеты в соответствии с размером –

+0

. Я добавил небольшой размер, но он все тот же. Моя проблема - это расстояние между кнопками, а не размер кнопки – kobbycoder

0

Попытайтесь использовать Relative Layout или Frame Layout вместо Linear Layout.

Смежные вопросы