首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android将textview与textview对齐

Android将textview与textview对齐
EN

Stack Overflow用户
提问于 2015-06-18 15:10:00
回答 1查看 54关注 0票数 0

下面有代码。我需要对齐文本视图与文本视图。使用id:test1 1的第一行非常长,第二个文本视图应该与第一个文本视图( test1 )对齐到它的末尾。有什么帮助吗?

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-18 15:15:47

你需要让它们扩展到触点。

在两种情况下都使用layout_weight

代码语言:javascript
复制
<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 0dplayout_weight of 0.5 (out of 0.5)的意思是“我不提供宽度,直到它达到50%为止”。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30919224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档