我正在尝试在我的Android应用程序中对齐三个textview块。这是这种情况:我的第一个区块(发布日期)在左侧正确对齐,而第三个区块(语言)在右侧正确对齐。现在,我试图将第二个块放在上面两个之间的中间,但是您可以看到它位于第一个块的左侧。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/container">
<!-- BLOCK 1 -->
<TextView
android:layout_marginTop="16dp"
android:id="@+id/releaseDateHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:textColor="#ffffff"
android:text="Release Date"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:textStyle="bold"/>
<TextView
android:layout_below="@id/releaseDateHeader"
android:id="@+id/releaseDateTextView"
android:layout_width="wrap_content"
android:ellipsize="end"
android:textColor="#ffffff"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
tools:text="ff"/>
<!-- BLOCK 2 -->
<TextView
android:layout_marginTop="16dp"
android:id="@+id/runtimeHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:textColor="#ffffff"
android:text="Runtime"
android:layout_alignRight="@id/releaseDateHeader"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:textStyle="bold"/>
<TextView
android:layout_below="@id/runtimeHeader"
android:id="@+id/runtimeTextView"
android:layout_width="wrap_content"
android:ellipsize="end"
android:textColor="#ffffff"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
tools:text="ff"/>
<!-- BLOCK 3 -->
<TextView
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:id="@+id/countryHeader"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:textColor="#ffffff"
android:text="Language"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
android:textStyle="bold"/>
<TextView
android:layout_below="@id/countryHeader"
android:id="@+id/countryTextView"
android:layout_marginRight="16dp"
android:layout_width="wrap_content"
android:layout_alignParentEnd="true"
android:ellipsize="end"
android:textColor="#ffffff"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
tools:text="ff"/>
Use
layout_weight
like this:采用
it makes
View
align its left edge to right edge ofdesired_id
and right edge to left edge ofdesired_id
so
runtimeHeader
should betoRightOf
countryHeader
andtoLeftOf
releaseDateHeader
. also removelayout_alignRight