TextView android:ellipsize="marquee";没有按预期工作 [英] TextView android:ellipsize="marquee" not working as expected

查看:32
本文介绍了TextView android:ellipsize="marquee";没有按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ListView 中有一些自定义元素,据了解,每个元素都只是 LinearLayout 中的一个 TextView.当文本太长时,我希望 TextView 中的文本是水平滚动的单行.我阅读了很多关于此的帖子,我想出了一个应该可行的解决方案,但是我没有滚动全文,而是将文本剪切到包含视图的长度并以三个点结束.我不想要三个点,但需要滚动整个文本.

I have some custom elements in a ListView and each element is, up to know, just a TextView in a LinearLayout. I would like the text inside the TextView to be a single line scrolling horizontally when the text is too long. I read many posts on this and I came up with a solution that was supposed to work, but instead of having the full text scrolling I have the text cut to the length of the containing View and ended with the three dots. I don't want the three dots but the entire text needs to be scrolled.

这是列表中项目的布局(list_item.xml)

This is the layout of the items in the list (list_item.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listItem"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/list_item_selector"
    android:orientation="horizontal"
    android:paddingBottom="7dp"
    android:paddingLeft="15dp"
    android:paddingTop="7dp" >

    <TextView
        android:id="@+id/listText"
        style="@style/Text_View_Style_White"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever" 
        android:padding="3dp"

        android:selectAllOnFocus="true"
        android:singleLine="true"
        android:textColor="@drawable/list_item_text_selector" />


</LinearLayout>

我也尝试过 android:focusable="true"android:scrollHorizo​​ntally="true"android:maxLines="1"> 属性,但它们都不起作用.在适配器(扩展 BaseAdapter)的 getView() 方法中,我在返回 View 之前在 TextView 上使用了 setSelected(true) 方法.

I tried also with android:focusable="true", android:scrollHorizontally="true" and android:maxLines="1" attributes but none of them is working. In the getView() method of the adapter (which extends a BaseAdapter) I use the setSelected(true) method on the TextView, before returning the View.

我无法弄清楚问题是什么.任何帮助将不胜感激.

I can't figure out what the problem is. Any help will be highly appreciated.

推荐答案

正如@iDroid Explorer 所指出的,发布和接受答案可能对其他人有所帮助.改编自我对汤姆评论的回复:

As @iDroid Explorer pointed out, posting and accepting the answer can be of help to someone else. Adapting from my reply to Tom's comment:

我找到了解决问题的方法.经过一些尝试,我意识到问题是 android:selectAllOnFocus="true" 行(阅读@Tom 对可能原因的解释).我刚刚删除了那条线,现在一切正常很好,文本是完整的,并且在滚动时按需要滚动对于包含视图来说太长了.

I found the solution to my problem. After some attempts I've realized that the problem was the android:selectAllOnFocus="true" line (Read @Tom's explanation for probabale reason). I just removed that line and now everything is working very well, the text is complete and scrolling like desired when it is too long for the containing view.

这篇关于TextView android:ellipsize="marquee";没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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