2017-02-13 437 views
1

我已阅读约Android中的ConstraintLayout现在我有不同大小的TextView,但我想使用BaseLine约束来水平对齐两个文本视图的内容处理。如何在XML布局中实现这一点?如何在ConstraintLayout中使用BaseLine Constraint Constraint来水平对齐两个TextView 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的基线这可以在布局编辑器进行设置。 layout_constraintBaseline_toBaselineOf属性

app:layout_constraintBaseline_toBaselineOf="@+id/text1" 

Constraint Layout

Useful link on Constraint Layout

这可以在XML使用应用程式设定