2017-02-15 62 views
7

Android için yeni ve alt gezinme çubuğunda 3'ten fazla eleman bulunan bir uygulamayı yapmaya çalışıyorum. Onları gösterebiliyorum ama sonunda kümeleniyorlar ve sadece üç tanesi düzgün görülebilir. İşteAlttan navigasyon çubuğunda en fazla 3 öğe android

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/bottomNavigation" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:elevation="15dp" 
    android:layout_gravity="bottom" 
    android:layout_alignParentBottom="true" 
    app:menu="@menu/bottom_nav_items" /> 

bakış görüntüsü olduğu: İşte benim kodudur This is the snapshot

ben yardım lütfen şaşırıp ..

+0

Seçilen öğe her zaman (sayfanın başlığı göstermek zorundadır göz önüne alındığında) alan daha büyük bir miktarda olacaktır. Başka bir öğe seçtiğinizde genişler mi? – ianhanniballake

cevap

3

Emin değilim ama bildiğim kadarıyla, öyle değil mi hizalamayı bozmadan alt çubuğu kullanarak 3'ten fazla ürüne eşlik etmek mümkündür. Ne neyse yapabilirsiniz yatay yönde doğrusal bir düzen yapabilir, ve bu daha sonra görüntü görünümleri gibi bu simgeleri ayarlamak ve sonra Burada 1.

kodu olarak ağırlıklarını yapmak,

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:gravity="center" 
    android:layout_alignParentBottom="true" 
    android:background="#fff"> 

     <ImageView 
      android:layout_width="25dp" 
      android:layout_height="25dp" 
      android:src="(YOUR IMAGE SOURCE)" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" 
      android:layout_weight="1"/> 

Ve Bunun gibi diğer görüntü görünümleri.

14

Kümelenmiş menü öğelerini almamak için aşağıdaki yöntemi kullanabilirsiniz. Bu yöntemi BottomNavigationView komutunu kullanarak onCreate yönteminde çağırmalısınız.

// Method for disabling ShiftMode of BottomNavigationView 
private void disableShiftMode(BottomNavigationView view) { 
    BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0); 
    try { 
     Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode"); 
     shiftingMode.setAccessible(true); 
     shiftingMode.setBoolean(menuView, false); 
     shiftingMode.setAccessible(false); 
     for (int i = 0; i < menuView.getChildCount(); i++) { 
      BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i); 
      item.setShiftingMode(false); 
      // set once again checked value, so view will be updated 
      item.setChecked(item.getItemData().isChecked()); 
     } 
    } catch (NoSuchFieldException e) { 
     Log.e("BNVHelper", "Unable to get shift mode field", e); 
    } catch (IllegalAccessException e) { 
     Log.e("BNVHelper", "Unable to change value of shift mode", e); 
    } 
} 
+0

güzel çalışıyor –

+0

Teşekkürler. Birisine yardım ettiğim için mutluyum .. @ a.g.thamays –

1
 <android.support.design.widget.BottomNavigationView 
      android:id="@+id/navigation" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:background="?android:attr/windowBackground" 
      app:menu="@menu/navigation" /> 


navigation.xml(inside menu) 
<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <item 
     android:id="@+id/navigation_home" 
     android:icon="@drawable/ic_home_black_24dp" 
     android:title="@string/title_home" 
     app:showAsAction="always|withText" 
     android:enabled="true"/> 

    inside oncreate method 
    BottomNavigationView navigation = (BottomNavigationView)findViewById(R.id.navigation); 
     BottomNavigationViewHelper.disableShiftMode(navigation);//Dont forgot this line 




    public class BottomNavigationViewHelper { 
     public static void disableShiftMode(BottomNavigationView view) { 
      BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0); 
      try { 
       Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode"); 
       shiftingMode.setAccessible(true); 
       shiftingMode.setBoolean(menuView, false); 
       shiftingMode.setAccessible(false); 
       for (int i = 0; i < menuView.getChildCount(); i++) { 
        BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i); 
        //noinspection RestrictedApi 
        item.setShiftingMode(false); 
        // set once again checked value, so view will be updated 
        //noinspection RestrictedApi 
        item.setChecked(item.getItemData().isChecked()); 
       } 
      } catch (NoSuchFieldException e) { 
       Log.e("BNVHelper", "Unable to get shift mode field", e); 
      } catch (IllegalAccessException e) { 
       Log.e("BNVHelper", "Unable to change value of shift mode", e); 
      } 
     } 
    } 
+0

mükemmel, benim için çalışıyor, ama bir yardımcı sınıfta bu açıklamayı @SuppressLint ("RestrictedApi") koymak zorundayım. bu iyi bir uygulama mı? – Vrajesh