Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align ImageView to TextView baseline with ConstraintLayout

Is it possible to align the bottom of an ImageView to the baseline of a TextView using a ConstraintLayout? It used to be easy with a RelativeLayout but it seems to be gone from ConstraintLayout. :(

like image 293
Barry Fruitman Avatar asked Jun 05 '18 21:06

Barry Fruitman


Video Answer


1 Answers

yes, it can be achieved in constraintLayout using

android:baselineAlignBottom="true"
app:layout_constraintBaseline_toBaselineOf="@+id/textView"


please check below code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="wrap_content"
        android:layout_height="52dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:baselineAlignBottom="true"
        app:layout_constraintBaseline_toBaselineOf="@+id/textView33"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.815"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/home_96" />

    <TextView
        android:id="@+id/textView33"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.59"
        app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
like image 176
Moustafa EL-Saghier Avatar answered Sep 30 '22 21:09

Moustafa EL-Saghier