ConstraintLayout 无法对齐两个视图
ConstrainLayout not able to align two views
我想将 Sachin Textview 与 Tendulkar Textview 对齐。
截图:
设计时间我正在正确对齐。但它在应用程序中失败。
XML:
<TextView
android:id="@+id/tvFirstName"
style="@style/MediumBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
android:text="First Name: "
app:layout_constraintHorizontal_bias="0.09"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvLastName"
style="@style/MediumBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name: "
app:layout_constraintLeft_toLeftOf="@+id/tvFirstName"
app:layout_constraintTop_toBottomOf="@+id/tvFirstName"
android:layout_marginLeft="0dp"
android:layout_marginTop="-10dp" />
<TextView
android:id="@+id/textView4"
style="@style/SmallGray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:text="Sachin"
app:layout_constraintLeft_toRightOf="@+id/tvFirstName"
app:layout_constraintBaseline_toBaselineOf="@+id/tvFirstName" />
<TextView
android:id="@+id/textView2"
style="@style/SmallGray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tendulkar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBaseline_toBaselineOf="@+id/tvLastName"
app:layout_constraintHorizontal_bias="0.47" />
is there any android studio-constraintlayout specific feature?
您对 "Tendulkar" 的限制导致 TextView
居中。您想要将 TextView
的左侧与 "Sachin" 的左侧对齐,如下所示:
<TextView
android:id="@+id/textView2"
style="@style/SmallGray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tendulkar"
app:layout_constraintLeft_toLeftOf="@id/textView4"
app:layout_constraintBaseline_toBaselineOf="@+id/tvLastName"/>
我也去掉了偏见。
我想将 Sachin Textview 与 Tendulkar Textview 对齐。
截图:
设计时间我正在正确对齐。但它在应用程序中失败。
XML:
<TextView
android:id="@+id/tvFirstName"
style="@style/MediumBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
android:text="First Name: "
app:layout_constraintHorizontal_bias="0.09"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvLastName"
style="@style/MediumBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name: "
app:layout_constraintLeft_toLeftOf="@+id/tvFirstName"
app:layout_constraintTop_toBottomOf="@+id/tvFirstName"
android:layout_marginLeft="0dp"
android:layout_marginTop="-10dp" />
<TextView
android:id="@+id/textView4"
style="@style/SmallGray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:text="Sachin"
app:layout_constraintLeft_toRightOf="@+id/tvFirstName"
app:layout_constraintBaseline_toBaselineOf="@+id/tvFirstName" />
<TextView
android:id="@+id/textView2"
style="@style/SmallGray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tendulkar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBaseline_toBaselineOf="@+id/tvLastName"
app:layout_constraintHorizontal_bias="0.47" />
is there any android studio-constraintlayout specific feature?
您对 "Tendulkar" 的限制导致 TextView
居中。您想要将 TextView
的左侧与 "Sachin" 的左侧对齐,如下所示:
<TextView
android:id="@+id/textView2"
style="@style/SmallGray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tendulkar"
app:layout_constraintLeft_toLeftOf="@id/textView4"
app:layout_constraintBaseline_toBaselineOf="@+id/tvLastName"/>
我也去掉了偏见。