下面有代码。我需要对齐文本视图与文本视图。使用id:test1 1的第一行非常长,第二个文本视图应该与第一个文本视图( 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>发布于 2015-06-18 15:15:47
你需要让它们扩展到触点。
在两种情况下都使用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>layout_width of 0dp和layout_weight of 0.5 (out of 0.5)的意思是“我不提供宽度,直到它达到50%为止”。
https://stackoverflow.com/questions/30919224
复制相似问题