Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – TextView中的自动水平滚动大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有自定义画廊.
图库表示框架布局的项目.
上面有一个imageView和textView.

如果textView中的文本太长,我需要它自动滚动.
它是一行文本,需要水平滚动.@H_489_6@

发现了这段代码:@H_489_6@

TextView
    android:text="Single-line text view that scrolls automatically"       
    android:singleLine="true" 
    android:ellipsize="marquee"
    android:marqueeRepeatLimit ="marquee_forever"
    android:focusable="true"
    android:focusableInTouchMode="true" 
    android:scrollHorizontally="true"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>

它适用于我的测试应用程序,其中只有一个文本视图.
它在我的画廊中不起作用.注意到,文字只是保持不动.@H_489_6@

有帮助吗?@H_489_6@

解决方法

试试这个自定义TextView类:
public class AutoScrollingTextView extends TextView {
    public AutoScrollingTextView(Context context,AttributeSet attrs,int defStylE) {
        super(context,attrs,defStylE);
    }

    public AutoScrollingTextView(Context context,AttributeSet attrs) {
        super(context,attrs);
    }

    public AutoScrollingTextView(Context context) {
        super(context);
    }

    @Override
    protected void onFocusChanged(Boolean focused,int direction,Rect prevIoUslyFocusedRect) {
        if (focused) {
            super.onFocusChanged(focused,direction,prevIoUslyFocusedRect);
        }
    }

    @Override
    public void onWindowFocusChanged(Boolean focused) {
        if (focused) {
            super.onWindowFocusChanged(focused);
        }
    }

    @Override
    public Boolean isFocused() {
        return true;
    }
}

并设置以下XML属性:@H_489_6@

android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"

这在我的词典应用程序中非常有效,其中多个条目可能需要同时自动滚动以显示完整内容.@H_489_6@

大佬总结

以上是大佬教程为你收集整理的android – TextView中的自动水平滚动全部内容,希望文章能够帮你解决android – TextView中的自动水平滚动所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。