在android中更改自定义底部导航栏中图标和文本的对齐方式

在android中更改自定义底部导航栏中图标和文本的对齐方式,android,bottomnavigationview,Android,Bottomnavigationview,我正在使用com.luseen.spacenavigation.SpaceNavigationView作为自定义导航栏。它工作正常,但我的问题是底部导航栏中图标和文本的对齐。它水平对齐,但我希望文本在图标下方对齐。如何更改对齐方式 我的XML <com.luseen.spacenavigation.SpaceNavigationView android:id="@+id/space" android:layout_width="match_parent" andro

我正在使用com.luseen.spacenavigation.SpaceNavigationView作为自定义导航栏。它工作正常,但我的问题是底部导航栏中图标和文本的对齐。它水平对齐,但我希望文本在图标下方对齐。如何更改对齐方式

我的XML

<com.luseen.spacenavigation.SpaceNavigationView
    android:id="@+id/space"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    app:active_item_color="@color/colorAccent"
    app:centre_button_color="@android:color/holo_green_light"
    app:inactive_item_color="@android:color/darker_gray"
    app:space_background_color="@android:color/holo_green_light"
    app:centre_button_icon="@drawable/img1"
    app:space_item_icon_size="@dimen/space_item_icon_default_size"
    app:space_item_icon_only_size="@dimen/space_item_icon_only_size"
    app:space_item_text_size="@dimen/space_item_text_default_size"
    app:layout_behavior="com.luseen.spacenavigation.SpaceNavigationViewBehavior"/>
要解决此问题,必须在库中编辑space\u item\u view.xml布局文件

space\u item\u view.xml

    <RelativeLayout
    android:id="@+id/main_content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/space_icon"
        android:layout_width="@dimen/space_item_icon_default_size"
        android:layout_gravity="center"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_height="@dimen/space_item_icon_default_size" />

    <TextView
        android:id="@+id/space_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:lines="1"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/space_icon"
        android:gravity="center"
        android:textSize="@dimen/space_item_text_default_size"
        tools:text="Label One" />
    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/badge_container"
    android:layout_width="16dp"
    android:layout_height="16dp"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="@dimen/badge_left_margin"
    android:layout_marginRight="2dp"
    android:layout_marginTop="3dp"
    android:layout_toRightOf="@+id/main_content"
    android:visibility="gone">
    <TextView
        android:id="@+id/badge_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textColor="@android:color/white"
        android:textSize="10sp"
        android:textStyle="bold" />
</RelativeLayout>
在您想要实现此功能的活动/片段中,只需替换spaceNavigationView.showiconly;至spaceNavigationView.showiconlyFalse


中找到您是指此库?是的,实现'com.github.armcha:SpaceNavigationView:1.6.0'此实现我正在gradle文件中使用此实现,因此如何编辑它?1.克隆项目。将rspacelib目录复制到您的应用程序。3.像这样改变你的等级
    <RelativeLayout
    android:id="@+id/main_content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/space_icon"
        android:layout_width="@dimen/space_item_icon_default_size"
        android:layout_gravity="center"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_height="@dimen/space_item_icon_default_size" />

    <TextView
        android:id="@+id/space_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:lines="1"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/space_icon"
        android:gravity="center"
        android:textSize="@dimen/space_item_text_default_size"
        tools:text="Label One" />
    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/badge_container"
    android:layout_width="16dp"
    android:layout_height="16dp"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="@dimen/badge_left_margin"
    android:layout_marginRight="2dp"
    android:layout_marginTop="3dp"
    android:layout_toRightOf="@+id/main_content"
    android:visibility="gone">
    <TextView
        android:id="@+id/badge_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textColor="@android:color/white"
        android:textSize="10sp"
        android:textStyle="bold" />
</RelativeLayout>
public void showIconOnly(boolean value) {
    isIconOnlyMode = value;
}