0

我想對齊Sachin Textview with Tendulkar Textview。ConstrainLayout無法對齊兩個視圖

截圖: enter image description here

設計時間我得到正確對齊。但它在應用程序中失敗。

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" /> 

有任何Android工作室constraintlayout特定的功能?

回答

0

對「Tendulkar」的限制導致TextView居中。要對齊該TextView的左側與「薩欽」的左側如下:

<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"/> 

我也去掉了偏見。