0

I am trying to make custom bottom bar (strictly I cannot use library). There I have five images and text below it. Also I have notification badge count on exactly two icons. My problem is the spacing between the icon and text below does not remain equal, also when I add badge icon it gets disturbed, so how to align them properly.

<?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>
Sambit Mallick
  • 155
  • 4
  • 14
Pritish
  • 1,284
  • 1
  • 19
  • 42

1 Answers1

0

I faced similar situation while placing text under RadioButton with equal spacing using LinearLayout. Using similar layout I hope It'll solve the problem.

<?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>
Sambit Mallick
  • 155
  • 4
  • 14