两个TextViews并排,只有一到ellipsize? [英] Two TextViews side by side, only one to ellipsize?

查看:121
本文介绍了两个TextViews并排,只有一到ellipsize?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有两个的TextView 元素并排显示(在列表项),一个左对齐,一个向右。是这样的:

  |< TextView的> < TextView的> |
 

(即 | 重present屏幕的四肢)

在左侧然而,的TextView 可以拥有的内容是太长,不适合在屏幕上。在这种情况下,我想拥有它ellipsize,但仍然显示了整个右的TextView 。是这样的:

  |这是很多小故事...< TextView的> |
 

我曾无数次尝试,在此,同时使用的LinearLayout RelativeLayout的,唯一的解决办法,我来了与是使用 RelativeLayout的,把一个 marginRight 左侧的TextView 大到足以清除右的TextView 。你可以想像,不过,这并不是最佳选择。

还有没有其他的解决方案?

最后,的LinearLayout 解决方法:

 <的LinearLayout
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =FILL_PARENT
    机器人:方向=横向
    >
    <的TextView
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:ellipsize =结束
        机器人:inputType =文本
        />
    <的TextView
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_weight =0
        机器人:layout_gravity =右
        机器人:inputType =文本
        />
< / LinearLayout中>
 

老, TableLayout 解决方法:

 < TableLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:stretchColumns =1
    机器人:shrinkColumns =0
    >
    <的TableRow>
        < TextView的机器人:ID =@ + ID /标题
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:ellipsize =结束
            机器人:单线=真
            />
        < TextView的机器人:ID =@ + ID /日期
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:单线=真
            机器人:ellipsize =无
            机器人:重力=右
            />
    < /的TableRow>
< / TableLayout>
 

解决方案

使用tablelayout,把两个文本框的表行有一个尝试。我没有尝试过

I want to have two TextView elements appear side by side (in a list item), one aligned to the left, one to the right. Something like:

|<TextView>               <TextView>|

(the | represent the screen's extremities)

However, the TextView on the left can have content that is too long to fit on the screen. In this case, I want to have it ellipsize but still show the entire right TextView. Something like:

|This is a lot of conte...<TextView>|

I have had numerous attempts at this, using both LinearLayout and RelativeLayout, and the only solution I have come up with is to use a RelativeLayout and put a marginRight on the left TextView big enough to clear the right TextView. As you can imagine, though, this is not optimal.

Are there any other solutions?

Final, LinearLayout solution:

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    >
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:inputType="text"
        />
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_weight="0"
        android:layout_gravity="right"
        android:inputType="text"
        />
</LinearLayout>

Old, TableLayout solution:

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    android:shrinkColumns="0"
    >
    <TableRow>
        <TextView android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:singleLine="true"
            />
        <TextView android:id="@+id/date"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:singleLine="true"
            android:ellipsize="none"
            android:gravity="right"
            />
    </TableRow>
</TableLayout>

解决方案

USe tablelayout and put both textbox in table row have a try . i didn't tried

这篇关于两个TextViews并排,只有一到ellipsize?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆