Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align two TextView's horizontally using the BaseLine Constraint Handle in ConstraintLayout Android

I have read about ConstraintLayout in Android, Now I have TextView's of different sizes , but I want to align the content of two textviews horizontally using the BaseLine Constraint Handle. How to achieve this in xml layout ?

This is my layout.xml

<?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/image"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@mipmap/ic_launcher"/>

   <TextView
      android:id="@+id/text1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Hello World"
      app:layout_constraintLeft_toRightOf="@+id/image"
      app:layout_constraintTop_toBottomOf="@+id/image"
      android:layout_marginStart="24dp"
      android:layout_marginLeft="24dp"/>

   <TextView
      android:layout_width="wrap_content"
      android:layout_height="100dp"
      app:layout_constraintLeft_toRightOf="@+id/text1"
      android:textSize="50sp"
      android:text="Big Text"
      android:layout_marginStart="24dp"
      android:layout_marginLeft="24dp" />

</android.support.constraint.ConstraintLayout>
like image 398
Sasank Sunkavalli Avatar asked Feb 13 '17 11:02

Sasank Sunkavalli


1 Answers

This can be set in the layout editor by dragging the baseline handle of the desired TextView to the baseline of another TextView.

or

This can be set in the xml using the app:layout_constraintBaseline_toBaselineOf attribute

app:layout_constraintBaseline_toBaselineOf="@+id/text1"

Constraint Layout

Useful link on Constraint Layout

like image 136
Sasank Sunkavalli Avatar answered Sep 26 '22 08:09

Sasank Sunkavalli