如何在底部导航视图之间划分 space?

How divide space between Bottom Navigation View?

我需要创建带有两个菜单项的底部导航。但视图比例为 30:70 并且文本重心位于中心。 一个菜单包含图像和文本,一个只有文本

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

<item
    android:id="@+id/bottom_navigation_1"
    android:icon="@drawable/ic_symbol1"
    android:title="@string/bottom_navigation_title1"
    app:showAsAction="always|withText" />

<item
    android:id="@+id/bottom_navigation_2"
    android:icon="@drawable/ic_symbol2"
    android:title="@string/bottom_navigation_title2"
    app:showAsAction="always|withText" />

主布局中的代码下方

<android.support.design.widget.BottomNavigationView
    android:state_enabled="true"
    android:id="@+id/home_screen_bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/bottom_navigation1" />

您可以使用简单的 LinearLayout 和 weightsum 将您的权重与 70-30 相乘,以避免复杂的 BottomNavigation 菜单。使用 ImageView 和 TextView 设置一个具有垂直线性布局的视图,另一个视图仅使用 TextView。两个视图的父视图都是水平的 LinearLayout。

I need to create Bottom Navigation with two menu item. but the view ratio is 30:70 and text gravity is in centre. one menu contain image and text one is only text

AFAIK 你无法更好地使用菜单为此创建自定义布局

示例代码

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_margin="10dp"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:weightSum="1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/ic_message"
        android:gravity="center"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:textStyle="bold"
        android:textColor="#FFFFFF"
        android:background="#24edf1"
        android:text="Message" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".7"
        android:padding="5dp"
        android:textStyle="bold"
        android:textColor="#24edf1"
        android:background="#dedbdb"
        android:gravity="center"
        android:text="BUY" />

</LinearLayout>

输出