首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单行多行TextView和单线TextView

单行多行TextView和单线TextView
EN

Stack Overflow用户
提问于 2015-09-23 22:57:22
回答 2查看 748关注 0票数 0

我想在我的布局中得到下一个结果:左文本视图,右文本视图,为此,我使用它:

代码语言:javascript
复制
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingBottom="10dp"
    android:paddingTop="10dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="left"
        android:id="@+id/left"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="right"
        android:id="@+id/right"/>

</RelativeLayout>

没关系的。但是,如果左TextView包含一个大文本,结果将是下一个:

左文本视图(左文本视图右文本视图下)。所以左超右。但我希望左TextView不覆盖右,当左TextView到达右TextView时,左TextView进入多行。所以我想得到下一个结果:

一些-文本-文本-左-多行

一些-文本-文本-左-多行文本-右文本-视图

一些-文本-文本-左-多行

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-23 23:17:19

使用线性布局(水平)并将具有相同android:layout_weight的文本视图放置在内部,以进行50/50拆分

代码语言:javascript
复制
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/left"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/right"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />
</LinearLayout>

这会扩展左边,直到使用android:layout_toLeftOf到达右侧。

代码语言:javascript
复制
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/right"
        android:text="this is a long text on the left which should be multiline and it is" />

    <TextView
        android:id="@+id/right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="some text" />
</RelativeLayout>

票数 0
EN

Stack Overflow用户

发布于 2015-09-23 23:21:56

对您的布局执行以下操作:

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relativeLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:gravity="right"
            android:minWidth="50dp"
            android:maxWidth="100dp"
            android:text="right" />

        <TextView
            android:id="@+id/left"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:gravity="left"
            android:layout_toLeftOf="@+id/right"
            android:text="left" />


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

https://stackoverflow.com/questions/32750803

复制
相关文章

相似问题

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