简体   繁体   English

如何使用ConstraintLayout Android中的BaseLine约束句柄水平对齐两个TextView

[英]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. 我在Android中读过ConstraintLayout ,现在我有不同大小的TextView,但我想使用BaseLine Constraint Handle水平对齐两个textviews的内容。 How to achieve this in xml layout ? 如何在xml布局中实现这一点?

This is my layout.xml 这是我的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>

This can be set in the layout editor by dragging the baseline handle of the desired TextView to the baseline of another TextView. 这可以通过将所需TextView的基线句柄拖动到另一个TextView的基线来在布局编辑器中设置。

or 要么

This can be set in the xml using the app:layout_constraintBaseline_toBaselineOf attribute 这可以使用app:layout_constraintBaseline_toBaselineOf属性在xml中设置

app:layout_constraintBaseline_toBaselineOf="@+id/text1"

Constraint Layout 约束布局

Useful link on Constraint Layout 约束布局上的有用链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM