Why Android Constraint Baseline_toBaselineOf not working Vertically

Viewed 718
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/playButton"
        android:layout_width="73dp"
        android:layout_height="62dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@android:drawable/ic_media_play" />

        <ImageView
            android:id="@+id/nextMusic"
            android:layout_width="73dp"
            android:layout_height="62dp"
            android:layout_marginEnd="66dp"
            app:layout_constraintStart_toEndOf="@+id/playButton"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@+id/playButton"
            app:layout_constraintBottom_toBottomOf="@+id/playButton"
            app:layout_constraintBaseline_toBaselineOf="@+id/playButton"
            app:srcCompat="@android:drawable/ic_media_next" />

        <ImageView
            android:id="@+id/previousMusic"
            android:layout_width="73dp"
            android:layout_height="62dp"
            android:layout_marginStart="84dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/playButton"
            app:layout_constraintBottom_toBottomOf="@+id/playButton"
            app:layout_constraintBaseline_toBaselineOf="@+id/playButton"
            app:srcCompat="@android:drawable/ic_media_previous" />
    </androidx.constraintlayout.widget.ConstraintLayout>

I'm trying to align these three widgets by "app:layout_constraintBaseline_toBaselineOf", however, as shown on the result below, it does not seem to align properly:

enter image description here

How could I align them and send them to the screen bottom?

1 Answers

ImageViews don't have baselines, so remove all baseline constraints. Remove the app:layout_constraintTop_toTopOf="parent" constraint on the play button. This will send the play button to the bottom of the screen. (Constraining to the top and the bottom centers the widget.)

Once the play button is at the bottom, you can then adjust the other views. See the documentation for ConstraintLayout.

Related