-5

在此处输入图像描述

我需要使用两个菜单项创建底部导航。但视图比例为 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" />
4

2 回答 2

1

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

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>

输出

在此处输入图像描述

于 2018-04-18T03:56:51.533 回答
0

您可以使用简单的 LinearLayout 和 weightsum 将您的体重降低 70-30 以避免复杂的底部导航菜单。使用 ImageView 和 TextView 设置一个具有垂直线性布局的视图,以及仅使用 TextView 设置另一个视图。两个视图的父级都是水平线性布局。

于 2018-04-17T13:03:31.283 回答