Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Android ConstraintLayout: set one element in the center of another one

I’m using ConstraintLayout in order to create activity view

There is a code snippet:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:orientation="vertical"
    tools:context=".presentation.screens.registration.RegistrationActivity">

    <LinearLayout>...</LinearLayout>

    <Button
        android:id="@+id/login_next_btn"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:background="@drawable/button_green_disabled"
        android:layout_width="match_parent"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="24dp"
        android:text="@string/next"
        android:textColor="@color/font_white"
        android:textSize="16sp"
        android:layout_height="48dp"
        android:enabled="false"
        android:onClick="onNextClick"/>

    <ImageView
        android:id="@+id/loader_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="@+id/login_next_btn"
        android:src="@drawable/ic_loader"/>


</androidx.constraintlayout.widget.ConstraintLayout>

The question is: How can I set ImageView (android:id="@+id/loader_image") in the center of Button (@+id/login_next_btn)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you have to set it in the center just change the constraints of the image with :

 app:layout_constraintBottom_toBottomOf="@id/login_next_btn"
 app:layout_constraintTop_toTopOf="@id/login_next_btn"
 app:layout_constraintStart_toStartOf="@id/login_next_btn"
 app:layout_constraintEnd_toEndOf="@id/login_next_btn"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading