Android的TextView的单线域隐藏长文本 [英] Android TextView SingleLine field hides long text

查看:151
本文介绍了Android的TextView的单线域隐藏长文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView它位于屏幕的左侧并且被设置与比重=右和它被设置用SINGLELINE =真。

如果由于某种在这个视图中的文本变得很长,我希望它完全消失过视图的左侧。我想下面的配置会做,但实际发生的事情是一长串完全消失,presumably下来,什么地方该视图之外。

我如何可以创建一个包含文本的一行,并保持其布局,即使某种意外情况的简单文本看法? ......甚至一些predictable。

 <的TextView
    机器人:ID =@ + ID / tempF
    机器人:文本=@字符串/ tempF
    机器人:layout_width =146dp
    机器人:layout_height =WRAP_CONTENT
    机器人:文字颜色=#CCCCCC
    机器人:TEXTSTYLE =黑体
    机器人:TEXTSIZE =92dp
    机器人:fontFamily中=衬线
    机器人:重力=右
    机器人:layout_marginTop =60dp
    机器人:layout_gravity =顶|左
    机器人:单线=真
    />
 

解决方案

这是ellipsize的宗旨 - 截断文本的一部分,表明附加文本

在你的情况下,你可能只需要添加类似:

 安卓ellipsize =终结
 

或你可能需要去深入:

<一个href="http://stackoverflow.com/questions/3288716/automatically-ellipsize-a-string-in-java">Automatically ellipsize一个字符串中的Java

或者看看这个:

安卓ellipsize多行的TextView

背后扩展类的想法是,你可以自定义的TextView的行为,当文本内容超过提供的空间。例如,可以通过去除填充等省略号给它的是流血了的出现是一种常用解释有,你看不到更多的文本的指标 - 这是它会如何看

这确实是一个很长的......

(3个周期是省略号 - 你的文字去相反的方向,但它应该仍然工作)

通过自定义的TextView,你可以改变的...不了了之或任何你想要的东西(甚至是一个形象,我已经做了)。

您也可以框选文字:

的TextView跑马灯不工作

I have a TextView which sits on the left side of the screen and is set with gravity="right" and it is set with SingleLine = "true."

If by some chance the text in this view gets too long I want it to simply disappear off the left hand side of the view. I thought the configuration below would do that but what actually happens is the the long string disappears completely, presumably down and outside of the view somewhere.

How can I create a simple text view that contains a single line of text and keeps its layout even when something unexpected happens? ... or even something predictable.

<TextView
    android:id="@+id/tempF"
    android:text="@string/tempF"
    android:layout_width="146dp"
    android:layout_height="wrap_content"
    android:textColor="#cccccc"
    android:textStyle="bold"
    android:textSize="92dp"
    android:fontFamily="serif"
    android:gravity="right"
    android:layout_marginTop="60dp"
    android:layout_gravity="top|left"
    android:singleLine="true"
    />

解决方案

This is the purpose of "ellipsize" - truncating a portion of text to indicate additional text.

In you case, you may simply need to add something like:

android:ellipsize="end"

or you might need to go deeper:

Automatically ellipsize a string in Java

Or look at this:

android ellipsize multiline textview

The idea behind extending the class is that you can customize the behavior of the TextView when the text content exceeds the space provided. For example, you can give it the appearance the it "bleeds over" by removing padding, etc. An ellipsis is an indicator that is commonly used to explain "there's more text that you can't see" - this is how it would look:

This is really a really long...

(the 3 periods are the ellipsis - your text goes the opposite direction, but it should still work)

With a custom TextView, you could change the "..." to nothing or anything else you want (even an image, which I've done).

You could also marquee the text:

TextView Marquee not working

这篇关于Android的TextView的单线域隐藏长文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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