Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TextView隐藏了最后一个可以在空间中看到的单词_Android_Textview_Partial_Visible_Words - Fatal编程技术网

Android TextView隐藏了最后一个可以在空间中看到的单词

Android TextView隐藏了最后一个可以在空间中看到的单词,android,textview,partial,visible,words,Android,Textview,Partial,Visible,Words,例如,我们有两个单词的组合:第一个单词第二个单词。 Textview有一行,它的宽度不大,所以第一个字是可见的,第二个字是长的,以适应静态空间,它不可见:[Firstword\uuuuuuuuuuuu] 如何实现第二个单词的局部可见性? 像这样[Firstword secon]或[Firstword seco…]加上省略。可能吗? 我在一些主题中看到,我想要的是使用ellipsize时的默认行为,但在我的例子中不是这样 编辑:android:ellipsize=end android:maxLi

例如,我们有两个单词的组合:第一个单词第二个单词。 Textview有一行,它的宽度不大,所以第一个字是可见的,第二个字是长的,以适应静态空间,它不可见:[Firstword\uuuuuuuuuuuu] 如何实现第二个单词的局部可见性? 像这样[Firstword secon]或[Firstword seco…]加上省略。可能吗? 我在一些主题中看到,我想要的是使用ellipsize时的默认行为,但在我的例子中不是这样


编辑:android:ellipsize=end android:maxLines=1只能在xml布局预览中工作,但不能在运行时工作。

将这些添加到文本视图中

android:ellipsize=end android:maxLines=1


如果我了解您希望以编程方式设置为textView的内容,请执行以下操作:

textView.setEllipsize(TextUtils.TruncateAt.END);
找到了解决办法

此xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv1"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:singleLine="true"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv2"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:lines="1"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv3"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:maxLines="1"/>
</LinearLayout>
在设计预览中渲染

好的,所有的椭圆人都在这里工作。 但在真正的设备上它看起来像

android:singleLine=true只起作用,尽管它已被弃用。
在3台设备上测试

是的,这是xml布局预览中的工作。但在运行时不起作用。显示[Firstword…\uu____]可能是因为我使用自定义TextView和自己的ttf字体?TextView.setEllipsizeTextUtils.TruncateAt.END;textView.setEllipsizeTextUtils.TruncateAt.END也不起作用。即使使用默认的TextView。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv1"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:singleLine="true"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv2"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:lines="1"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Helloooooooooooooooooooooo Wooooooooooooooooooooooooorld!"
        android:id="@+id/tv3"
        android:textColorLink="@android:color/holo_blue_dark"
        android:ellipsize="end"
        android:maxLines="1"/>
</LinearLayout>