Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.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:ellipsize=";开始;?_Android_Textview - Fatal编程技术网

我如何获得一个溢出的文本视图来使用android:ellipsize=";开始;?

我如何获得一个溢出的文本视图来使用android:ellipsize=";开始;?,android,textview,Android,Textview,在我的应用程序中,我经常在以下布局中动态更新TextView的内容: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/container_vie

在我的应用程序中,我经常在以下布局中动态更新TextView的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container_view"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="@dimen/top_padding"
    android:paddingRight="@dimen/side_padding"
    android:paddingBottom="@dimen/top_padding"
    android:paddingLeft="@dimen/side_padding">

    <TextView
        android:id="@+id/breadcrumbs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title_showcase"
        style="@style/ShowcaseBreadcrumbs"
        android:ellipsize="start"
        android:singleLine="true" />

    <it.sephiroth.android.library.widget.HListView
        android:id="@+id/item_carousel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_marginTop="-40dp"
        android:listSelector="@android:color/transparent"
        app:hlv_dividerWidth="10dp"
        />

</LinearLayout>
我使用基本的
TextView.setText(String)
更新TextView的内容。不幸的是,当文本足够长时,TextView不会省略任何内容,因为溢出的文本刚刚从屏幕上消失:


我如何强制TextView显示其内容的结尾并在开始时正确省略?

显然,我遇到了Android省略号功能和辅助功能服务的错误。多亏了安卓bug追踪器上的一个测试,我发现LastPass可访问性服务(一个扫描应用程序以自动填充潜在用户名/密码框的服务)正在将文本视图的内容跳回开始。关闭LastPass服务解决了此问题

查看我拍摄的这个bug的屏幕记录(注意按钮上方的TextView):

我还使用对讲服务对其进行了测试——当该服务打开时,TextView再次跳转,就像视频中一样。关闭服务并重新启动应用程序产生了预期的效果


请注意,我不必更改XML中的任何内容—将服务切换为Off就足以解决问题。

Strange。我只使用
线性布局
文本视图
对您的代码片段进行了测试,测试结果完美无瑕。我猜父布局有问题。你能发布完整的XML布局吗?同样,我只是使用你的布局进行了测试,但我根本无法复制这个问题。无论如何,请尝试同时使用
android:maxLines=“1”
android:singleLine=“true”
。然后,尝试删除背景边框,看看它是否解决了问题。。。尽管我对此表示怀疑。除此之外,我可能再也帮不上忙了。@AndrewT。你在测试什么版本的Android和什么设备?我的Nexus 7 2013和我的Moto X(分别运行4.4和4.3)都不配合。奇怪的是,Android Studio中的预览正确地省略号,但一旦我在实际设备上查看布局,它就会做与我上面的问题相同的事情。我正在Nexus 4和LG phone(运行4.4.4和4.0.3)上测试它,它们都正确地显示省略号。我也很困惑,因为我没有从您的布局中看到任何可能的问题来源。你能用
LinearLayout
TextView
做一个非常简单的测试吗?这可能是2009年的一个老错误,它抬起了丑陋的头:它被标记为关闭,但最近有几个人(比如,今年)说他们遇到了同样的问题…很高兴知道你找到了原因和解决方案。我也从这个案例中学到了很多+1.
<style name="ShowcaseBreadcrumbs">
    <item name="android:textSize">32sp</item>
    <item name="android:background">@drawable/bottom_border_thin</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:layout_marginBottom">10dp</item>
</style>