bottomNavigationView 目的地可以水平定位而不是堆叠

Adr*_*era 5 android landscape material-design bottomnavigationview

我想要做的是我的 Android 项目中的底部导航视图的行为类似于 IOS 视图。当我将 Iphone 旋转到横向时,栏的高度较小,图标位于文本的一侧。

当手机处于垂直位置时,文本和图标应该堆叠。

在此处输入图片说明 当我旋转到横向时,文本和图标应该像这样水平显示。 在此处输入图片说明 这些图片来自材料文档:https : //material.io/design/components/bottom-navigation.html#placement

但是当我旋转到横向时,我找不到如何做第二个选项。有谁知道?

谢谢!

小智 3

我通过创建自定义布局解决了这个问题。的例子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>
Run Code Online (Sandbox Code Playgroud)

然后我将其添加到 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);
}
Run Code Online (Sandbox Code Playgroud)

你的视图在哪里mBinding.bottomNavigation(也许是 findViewById(R.id.bottomNavigationView) )

我希望它能帮助你!