下面有代码。我需要将textview与textview对齐。第一个id为:test1的第一个很长,有很多行,第二个textview应该对齐第一个test1到它的结尾。有什么帮助吗?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/standard_margin"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="VERY LONG STRING HERE"
android:textSize="@dimen/text_size_form"/>
<TextView
android:id="@+id/test2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textSize="@dimen/text_size_form"/>
</LinearLayout>
<TextView
android:id="@+id/abc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_form"/>
<TextView
android:id="@+id/abc1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_form"/>
</LinearLayout>
答案 0 :(得分:1)
您需要将它们展开以触摸。
在两者上使用layout_weight
。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/standard_margin"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/test1"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="VERY LONG STRING HERE"
android:textSize="@dimen/text_size_form"/>
<TextView
android:id="@+id/test2"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:text="123"
android:textSize="@dimen/text_size_form"/>
</LinearLayout>
<TextView
android:id="@+id/abc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_form"/>
<TextView
android:id="@+id/abc1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_form"/>
</LinearLayout>
<{1}} layout_width
0dp
layout_weight
(满分为1)表示&#34;我没有提供宽度,将其展开直至达到50%