Android TextView SingleLine 字段隐藏长文本 [英] Android TextView SingleLine field hides long text

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

问题描述

我有一个 TextView,它位于屏幕左侧,设置为重力 =right",它设置为 SingleLine = true".

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"
    />

推荐答案

这就是ellipsize"的目的——截断部分文本以指示附加文本.

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:

在Java中自动省略字符串

或者看看这个:

android ellipsize 多行文本视图

扩展类背后的想法是,当文本内容超出提供的空间时,您可以自定义 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:

这真的很长……

(这 3 个句点是省略号 - 您的文本方向相反,但它应该仍然有效)

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

使用自定义 TextView,您可以将..."更改为任何内容或您想要的任何其他内容(甚至是图像,我已经这样做了).

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

你也可以选中文本:

TextView 字幕不起作用

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

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