Sandeep Choudhary
Sandeep Choudhary

Reputation: 260

Checkboxes and TextInputLayout not getting properly aligned inside a linear layout

I'm having two checkboxes and a TextInputLayout inside a liner layout. But they ain't getting properly rendered. The checkboxes are shifting downwards. I tried everything and they are not aligning.

My code is as follows:

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

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layoutSysCardNo"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_weight="2"
            app:boxBackgroundColor="@color/white_50"
            app:counterMaxLength="10">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/sysCardNo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/field_enter_sys_job_no"
                android:inputType="number" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.checkbox.MaterialCheckBox
            android:id="@+id/hmsiWarranty"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_weight="1"
            android:text="@string/vehicle_delievered" />

        <com.google.android.material.checkbox.MaterialCheckBox
            android:id="@+id/extWarranty"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_weight="1"
            android:text="@string/vehicle_delievered" />

    </LinearLayout>

The output is as under

enter image description here

Upvotes: 0

Views: 589

Answers (1)

AskNilesh
AskNilesh

Reputation: 69709

Just use android:gravity="center" in your LinearLayout it will solve your problem

Try this

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:orientation="horizontal">

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layoutSysCardNo"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_weight="2"
            app:boxBackgroundColor="@color/white_50"
            app:counterMaxLength="10">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/sysCardNo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/field_enter_sys_job_no"
                android:inputType="number" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.checkbox.MaterialCheckBox
            android:id="@+id/hmsiWarranty"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_weight="1"
            android:text="@string/vehicle_delievered" />

        <com.google.android.material.checkbox.MaterialCheckBox
            android:id="@+id/extWarranty"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_weight="1"
            android:text="@string/vehicle_delievered" />

    </LinearLayout>

Upvotes: 1

Related Questions