2017-02-13 65 views
1

Я прочитал о ConstraintLayout в Android, Теперь у меня есть TextView-х разных размеров, но я хочу, чтобы выровнять содержимое двух TextViews по горизонтали с помощью Baseline Constraint Ручка. Как добиться этого в xml-макете?Как выровнять два TextView-х по горизонтали с помощью BaseLine Constraint ручки в ConstraintLayout Android

Это мой 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> 

ответ

3

Это может быть установлен в редакторе макета путем перетаскивания базовой ручки желаемого TextView к базовой линии другого TextView.

или

Это может быть установлен в XML с помощью приложения: layout_constraintBaseline_toBaselineOf атрибут

app:layout_constraintBaseline_toBaselineOf="@+id/text1" 

Constraint Layout

Useful link on Constraint Layout