带选框的 TextView 不起作用 [英] TextView with marquee is not working

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

问题描述

尽管我按照教程制作了一个 marquee TextView,并且当我尝试在不同的活动中制作另一个 TextView 作为 时它工作正常>marquee 它不起作用.我准确地遵循了相同的步骤,但无济于事.你认为我缺少什么?

Despite I managed to make a marquee TextView as I followed a tutorial, and it's working correctly, when I tried to make another TextView in a different activity as marquee it did not work. I followed the same step accurately but with no avail. what do you think I am missing?

更新

我认为问题出在视图的focus,因为我已经测试了即使在调用imgPathTv.setSelected(true)后TextView是否有焦点,结果是没有焦点.

I think the problem is in the focus of the view, because I have tested whether the TextView has focus even after calling imgPathTv.setSelected(true), and the result is it does not has the focus.

更新代码

String imgPath = dataBaseRow.getImgPath();
    if (imgPath.equals("")) {
        Log.d(TAG, "@createInfoReport(): dataBaseRow.getImgPath() Returns NULL");
        imgPathTv.setText("NULL");
    }else {
        Log.d(TAG, "@createInfoReport(): dataBaseRow.getImgPath() Has Value");

            imgPathTv.setSelected(true);
            imgPathTv.setText(imgPath);

            if(imgPathTv.findFocus() != null) {
                Toast.makeText(getApplicationContext(), "there is a View has the Focus", Toast.LENGTH_SHORT).show();
            }else
                Toast.makeText(getApplicationContext(), "NO View has the Focus", Toast.LENGTH_SHORT).show();
    }

Java_代码:

    TextView imgPathTv = (TextView) mDialog.findViewById(R.id.imgPathValue);
    Log.i(TAG, "@createInfoReport(): imgPathTv IS IN FOCUS");
    imgPathTv.setSelected(true);

TextView_xml:

TextView_xml:

<TextView 
                    android:id="@+id/imgPathValue"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:singleLine="true"
                    android:ellipsize="marquee"
                    android:marqueeRepeatLimit="marquee_forever"
                    android:scrollHorizontally="true"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:fadingEdge="horizontal"/>

推荐答案

也许您的文本长度不够长,无法让 Marquee 运行.换句话说,选取框仅在文本远大于其各自的宽度/区域时才起作用.因此,我建议尝试将 android:layout_width 设置为例如 200dp 甚至更多.然后尝试 marquee.我希望它有所帮助.

Maybe your text length is not long enough to let the Marquee runs. In other words, the marquee only works when the text is away larger than its respective width/area. So, I recommend to try to set the android:layout_width to be, for an example, 200dp or even more. then try the marquee. I hope it helps.

这篇关于带选框的 TextView 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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