Направления bottomNavigationView могут быть расположены горизонтально, а не сложены - PullRequest
0 голосов
/ 03 сентября 2018

Что я хочу сделать, так это то, что представление BottomNavigation в моем проекте Android ведет себя подобно IOS. Когда я поворачиваю Iphone в альбомную ориентацию, панель имеет меньшую высоту, а значки располагаются сбоку текста.

Когда мобильный телефон находится в вертикальном положении, текст и значки должны быть сложены.

enter image description here И когда я поворачиваюсь в альбомную ориентацию, текст и значки должны выглядеть горизонтально так. enter image description here Эти фотографии из материальной документации: https://material.io/design/components/bottom-navigation.html#placement

Но я не могу найти, как сделать второй вариант, когда я поворачиваюсь в ландшафт. Кто-нибудь знает?

Спасибо!

1 Ответ

0 голосов
/ 07 ноября 2018

Я решил это путем создания собственного макета. Пример item_bottom_navigation_bar.xml

<?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"
    android:orientation="horizontal"
    android:gravity="center"
    android:paddingTop="5dp">

    <ImageView
        android:id="@+id/icon"
        android:layout_margin="2dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

И затем я добавил его к каждому элементу моего BottomNavigationView:

LayoutInflater inflater = getLayoutInflater();
BottomNavigationMenuView navigationMenuView = (BottomNavigationMenuView) mBinding.bottomNavigation.getChildAt(0);
Menu menu = mBinding.bottomNavigation.getMenu();
for (int i = 0; i < menu.size(); i++) {
    BottomNavigationItemView view = (BottomNavigationItemView) navigationMenuView.getChildAt(i);
    View itemBottomNavigation = inflater.inflate(R.layout.item_bottom_navigation_bar, null, false);
    ((ImageView) itemBottomNavigation.findViewById(R.id.icon)).setImageDrawable(menu.getItem(i).getIcon());
    ((TextView) itemBottomNavigation.findViewById(R.id.title)).setText(menu.getItem(i).getTitle());
    view.removeAllViews();
    view.addView(itemBottomNavigation);
}

Где mBinding.bottomNavigation - это ваш View (может быть, findViewById (R.id.bottomNavigationView))

Надеюсь, это тебе поможет!

...