TextView Ellipsize (...) 不工作 [英] TextView Ellipsize (...) not working

查看:30
本文介绍了TextView Ellipsize (...) 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文本比 TextView 长时,我希望有一个单行 TextView 在末尾显示 3 个点.我不知道为什么 - 但我不明白.

I want to have a single lined TextView to show up 3 dots at the end when the text is longer than the TextView. I don't know why - but I don't get it.

我已经对类似的 StackOverflow 问题进行了思考,但我最终没有解决方案.也许有人有一些有用的提示.

I already wrapped my head around similar StackOverflow questions, but I ended up with no solution. Maybe someone has some useful hints.

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:orientation="vertical">

    <TextView 
        android:textStyle="bold" 
        android:text="Full Name" 
        android:layout_height="wrap_content" 
        android:textSize="16sp"
        android:layout_width="wrap_content" 
        android:id="@+id/lName"
        android:layout_gravity="center_vertical" 
        android:maxLines="1"
        android:ellipsize="end"/>
</LinearLayout>

上面的 LinearLayout 嵌套在另外 2 个 LinearLayouts 中.也许知道这一点很重要.我也已经尝试过属性singleLine",但有人说它已被弃用,无论如何它都不起作用.

The LinearLayout above is nested into 2 other LinearLayouts. Maybe this is important to know. I already tried the attribute "singleLine" too, but some say this is deprecated and it doesnt work anyway.

推荐答案

在您的样式文件中添加以下样式(通常是 styles.xml):

Add the following styles in your styles file (typically styles.xml):

<style name="autoscroll">
    <item name="android:singleLine">true</item>
    <item name="android:ellipsize">marquee</item>
    <item name="android:marqueeRepeatLimit">marquee_forever</item>
    <item name="android:focusable">true</item>
    <item name="android:focusableInTouchMode">true</item>
    <item name="android:scrollHorizontally">true</item>
</style>

然后将样式 @style/autoscroll 添加到您的 TextView:

Then add the style @style/autoscroll to your TextView:

<TextView android:id="@+id/lName"
      style="@style/autoscroll" />

您可以在需要时轻松重复使用自动滚动功能.

You can reuse your autoscroll feature easily when you want this way.

这篇关于TextView Ellipsize (...) 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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