小编lou*_*oox的帖子

2 个 TextView,左侧带省略号,右侧带 nowrap,单行

第一次在这个论坛发帖,希望一切顺利:)

我正在为我所在城市的公共交通开发 Android 应用程序。

这是我所拥有的

[ |short destination   ||next departure| ]
[ |way too long dest...||next departure| ]
Run Code Online (Sandbox Code Playgroud)

这就是我想要的:

[ |short destination||next departure|    ]
[ |way too long dest...||next departure| ]
Run Code Online (Sandbox Code Playgroud)

这是一个更完整的示例:s28.postimg.org/5gejnvfd9/actual2.png

奇怪的彩色背景只是为了轻松识别布局/文本视图。您也可以忽略棕色线(没关系)。

基本上,我想要具有可变长度的目的地[红色背景],在其右侧,我想要第一个出发时间[绿色背景]。一切都在一条线上。

我需要始终完整显示第一个出发信息(nowrap)。目的地可以用省略号 (...) 括起来。[可选问题,如何将省略号“...”替换为“.” ?]

这是迄今为止我拥有的最好的工作代码:

    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/txtTitleDestination"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/txtTitleFirstDeparture"
            android:background="#FF0000"
            android:ellipsize="end"
            android:maxLines="1"
            android:padding="0dp"
            android:scrollHorizontally="true"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/txtTitleFirstDeparture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="0dp"
            android:layout_alignParentRight="true"
            android:background="#00FF00"
            android:ellipsize="none"
            android:maxLines="1"
            android:padding="0dp"
            android:textSize="18sp"
            android:textStyle="bold" 
            />

    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我尝试过 TableLayout 和 LinearLayour 而不是relativelayout,但没有成功:(

知道我该怎么做吗?

提前致谢!

卢卢克斯

[已解决] …

android ellipsis textview nowrap

4
推荐指数
1
解决办法
1992
查看次数

标签 统计

android ×1

ellipsis ×1

nowrap ×1

textview ×1