0

我正在尝试制作自定义底栏(严格来说我不能使用库)。我在它下面有五个图像和文本。此外,我的通知徽章正好有两个图标。我的问题是图标和下面的文本之间的间距不相等,当我添加徽章图标时它也会受到干扰,所以如何正确对齐它们。

<?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="wrap_content"
    android:background="#FFFFFF"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/bottomBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false"
        android:paddingBottom="@dimen/fifteen_dp"
        android:gravity="center|center_horizontal"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.20"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="4dp">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/patients_disable"
                    android:visibility="visible" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/patients_enable"
                    android:visibility="gone" />

            </FrameLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center"
                android:text="PATIENTS"
                android:textSize="8sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.20"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="4dp">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/notifications_disable"
                    android:visibility="visible" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/notifications_enable"
                    android:visibility="gone" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="top|end"
                    android:layout_marginEnd="8dp"
                    android:minHeight="20dp"
                    android:minWidth="20dp"
                    android:background="@drawable/circle_bg"
                    android:text="4"
                    android:textAlignment="center"
                    android:textColor="#FFFFFF"
                    android:textSize="12sp"
                    android:visibility="visible" />

            </FrameLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center"
                android:text="NOTIFICATIONS"
                android:textAlignment="center"
                android:textSize="8sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.20"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:src="@drawable/search_disable"
                    android:visibility="visible" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/search_enable"
                    android:visibility="gone" />

            </FrameLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center"
                android:text="SEARCH"
                android:textSize="8sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.20"
            android:gravity="center_horizontal"
            android:orientation="vertical">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/reports_disable"
                    android:visibility="visible" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/reports_enable"
                    android:visibility="gone" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="top|end"
                    android:layout_marginEnd="8dp"
                    android:minHeight="20dp"
                    android:minWidth="20dp"
                    android:background="@drawable/circle_bg"
                    android:text="4"
                    android:textAlignment="center"
                    android:textColor="#FFFFFF"
                    android:textSize="12sp"
                    android:visibility="visible" />

            </FrameLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center"
                android:text="REPORTS"
                android:textSize="8sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.20"
            android:gravity="center_horizontal|center_vertical"
            android:orientation="vertical">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <ImageView

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:id="@+id/imgViewReport"
                    android:scaleType="centerInside"
                    android:src="@drawable/more_disable"
                    android:visibility="visible" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:id="@+id/imgView"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@drawable/more_active"
                    android:visibility="gone" />

            </FrameLayout>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="bottom"
                android:layout_gravity="bottom|center"
                android:text="PATIENTS"
                android:textSize="8sp" />

        </LinearLayout>   
    </LinearLayout>
</LinearLayout>
4

1 回答 1

0

在使用 LinearLayout 将文本以相等间距放置在 RadioButton 下时,我遇到了类似的情况。使用类似的布局,我希望它能解决问题。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="one" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="two" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="three" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="four" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="five" />

    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
于 2018-09-06T12:18:33.213 回答