为什么TextView的在elipsized与&QUOT单行;结束"显示框? [英] Why does TextView in single line elipsized with "end" show boxes?

查看:217
本文介绍了为什么TextView的在elipsized与&QUOT单行;结束"显示框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个TextView在Android中,我想显示1行的TextView与结局。但这给[]类型框底。我不知道为什么?我只是想remvoe此框,只显示文字与结局......

I'm using a TextView in Android, what I want to show 1 line in TextView ending with ". " but this give [] type box at the end. I don't know why? I just want to remvoe this box and only to show text ending with "... "

更新code为list_row.xml

Update code for the list_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="85dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:cacheColorHint="#4C7B8D"
android:background="#4C7B8D">
<ImageView
    android:id="@+id/videoListImage"
    android:src="@drawable/audio_thumbnail60x60"
    android:layout_height="75dp"
    android:layout_alignParentLeft="true"
    android:layout_centerInParent="true"
    android:scaleType="fitXY"
    android:layout_width="75dp"
    android:padding="4dp"
    android:background="@color/light_gray" />
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginRight="5dp"
        android:layout_toLeftOf="@+id/next_arrow"
        android:orientation="vertical"
        android:gravity="center_vertical"
        android:paddingLeft = "5dp">
        <TextView
            android:id="@+id/row_title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textColor="@color/app_background_color"
            android:textSize="18sp"
            android:ellipsize="end"             
            android:maxLines="1" />
        <TextView
            android:id="@+id/row_dis"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textColor="@color/color_black"
            android:layout_marginRight="2dp"
            android:textSize="15sp"
            android:ellipsize="end"
            android:maxLines="1" />
        <TextView
            android:text="$7.50"
            android:id="@+id/audio_price_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16dp"
            android:textColor="@color/color_white"
            android:textStyle = "bold"
            android:paddingLeft = "12dp"
            android:paddingRight = "12dp"
            android:background="@drawable/blue_round_cornor_background" />
    </LinearLayout>
    <ImageView
        android:id="@+id/next_arrow"
        android:src="@drawable/next_arrow"
        android:layout_toLeftOf="@+id/saved_purchased"
        android:scaleType="fitXY"
        android:layout_height="25dp"
        android:layout_width="18dp"
        android:layout_centerVertical="true"
        android:visibility = "gone"/>
    <ImageView
        android:id="@+id/saved_purchased"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop ="true"
        android:scaleType="fitXY"
        android:layout_height="25dp"
        android:layout_width="25dp"
        android:layout_marginRight="2dp"/>
</RelativeLayout>

下面是next_arrow的形象

Here is the images of "next_arrow"

下面是code我适配器使用getView()。

Here is the code I am using the getView() in adapter.

  String discription = listData.getDescription();
    if (discription != null && discription.length() > 0) {
        if (textViewDis != null) {
            textViewDis.setTypeface(titleFont);
            Log.e("data", ""+discription);
            discription.replaceAll("\r\n", "");
            textViewDis.setText(discription);
        }
    }

下面是描述的实际字符串的显示。

Here is the actual String of description to be display.

安德鲁和斯蒂芬妮·蒂德韦尔坦诚分享他们的成功故事在这个行业。这个故事将帮助大家听明白,没有一个人是完美的,即使是在第二代的业务。这是流式音频文件。

Andrew and Stephanie Tidwell candidly share their success story in this business. This story will help everyone listening realize that no one is perfect, even in a second generation business. This is a streaming audio file.

仍然有一些问题?我可以更新的问题更多。

Still have some issue? I can update question more.

推荐答案

引用我自己我的书之一:

Android的TextView的类有内置的能力ellipsize的文字,   截断它并添加一个省略号,如果文本比现有的长   空间。您可以通过Android使用:ellipsize属性,例如。   这工作还算不错,至少对单行文本。   是Android使用省略号不是三个时期。相反,它使用了一个实际的   省略号字符,其中所述三个点被包含在一个字形。   因此,你使用,你还可以使用ellipsizing功能的任何字体将   需要省略号字形。

Android's TextView class has the built-in ability to "ellipsize" text, truncating it and adding an ellipsis if the text is longer than the available space. You can use this via the android:ellipsize attribute, for example. This works fairly well, at least for single-line text. The ellipsis that Android uses is not three periods. Rather it uses an actual ellipsis character, where the three dots are contained in a single glyph. Hence, any font that you use that you also use the "ellipsizing" feature will need the ellipsis glyph.

除此之外,虽然,机器人垫出字符串获取屏幕上的呈现,使得所述长度(字符数)是相同的前,后   ellipsizing。为了使这项工作,机器人代替一个字符用   省略号,并取代所有其他的删除的字符与UNI code   字符ZERO WIDTH NO-BREAK SPACE(U + FEFF)。这意味着   额外字符的省略号后不占用任何可见的空间   屏幕上,但它们可以是字符串的一部分。

Beyond that, though, Android pads out the string that gets rendered on-screen, such that the length (in characters) is the same before and after "ellipsizing". To make this work, Android replaces one character with the ellipsis, and replaces all other removed characters with the Unicode character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF). This means the "extra" characters after the ellipsis do not take up any visible space on screen, yet they can be part of the string.

不过,这意味着你使用的TextView小部件的任何自定义字体,   你与Android使用:ellipsize也必须支持这个特殊的Uni code   字符。不是所有的字体做的,你会得到在屏幕上的文物   重新您缩短串presentation如果您的字体缺少这个人物   (例如,流氓X的出现在该行的末尾)。

However, this means any custom fonts you use for TextView widgets that you use with android:ellipsize must also support this special Unicode character. Not all fonts do, and you will get artifacts in the on-screen representation of your shortened strings if your font lacks this character (e.g., rogue X's appear at the end of the line).

这篇关于为什么TextView的在elipsized与&QUOT单行;结束&QUOT;显示框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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