Android 将文本视图与文本视图对齐
Android align textview to textview
下面有代码。我需要将 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>
您需要让它们展开以触摸。
两者都使用 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
with layout_weight
of 0.5
(out of 1) 表示“我不提供宽度,将其扩展到 50%。
下面有代码。我需要将 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>
您需要让它们展开以触摸。
两者都使用 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
with layout_weight
of 0.5
(out of 1) 表示“我不提供宽度,将其扩展到 50%。