web-dev-qa-db-ja.com

ConstraintLayoutのBaseLineConstraintHandleを使用して2つのTextViewを水平方向に配置する方法Android

AndroidでConstraintLayoutについて読みましたが、サイズの異なるTextViewがありますが、BaseLine ConstraintHandleを使用して2つの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>
7

これは、目的のTextViewのベースラインハンドルを別のTextViewのベースラインにドラッグすることにより、レイアウトエディターで設定できます。

または

これは、app:layout_constraintBaseline_toBaselineOf属性を使用してxmlで設定できます

app:layout_constraintBaseline_toBaselineOf="@+id/text1"

制約レイアウト

制約レイアウトの便利なリンク

19