【问题标题】:How to align two TextView's horizontally using the BaseLine Constraint Handle in ConstraintLayout Android如何使用 ConstraintLayout Android 中的 BaseLine 约束句柄水平对齐两个 TextView
【发布时间】:2017-02-14 00:46:40
【问题描述】:

我已经阅读了 Android 中的 ConstraintLayout,现在我有不同尺寸的 TextView,但我想使用 BaseLine 约束句柄水平对齐两个 textview 的内容。如何在 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>

【问题讨论】:

    标签: android android-constraintlayout


    【解决方案1】:

    这可以在布局编辑器中通过将所需 TextView 的基线句柄拖动到另一个 TextView 的基线来设置。

    这可以使用 app:layout_constraintBaseline_toBaselineOf 属性在 xml 中设置

    app:layout_constraintBaseline_toBaselineOf="@+id/text1"
    

    Constraint Layout

    Useful link on Constraint Layout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      相关资源
      最近更新 更多