android– 如何完全阻止TextView滚动?

android– 如何完全阻止TextView滚动?,第1张

概述我有一个带有大量文本的TextView.此TextView设置了maxLines,因此它仅显示前8行左右.我还有一个“阅读更多”按钮,所以我自己处理扩展TextView.我的问题是,有时TextView会滚动一点(一次只有半行),即使我从未指定任何滚动条.这个问题变得更糟,因为TextView在ListView中,所以当用户滚

我有一个带有大量文本的TextVIEw.此TextVIEw设置了maxlines,因此它仅显示前8行左右.我还有一个“阅读更多”按钮,所以我自己处理扩展TextVIEw.

我的问题是,有时TextVIEw会滚动一点(一次只有半行),即使我从未指定任何滚动条.这个问题变得更糟,因为TextVIEw在ListVIEw中,所以当用户滚动主ListVIEw时,TextVIEw有时会滚动一点,如下所示:

如何阻止TextVIEw滚动?

解决方法:

我有同样的问题,我的解决方案是创建一个NoScrollTextVIEw像这样扩展TextVIEw

 public class NoScrollTextVIEw extends TextVIEw {    public NoScrollTextVIEw(Context context) {        super(context);    }    public NoScrollTextVIEw(Context context, AttributeSet attrs) {        super(context, attrs);    }    public NoScrollTextVIEw(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @TargetAPI(Build.VERSION_CODES.LolliPOP)    public NoScrollTextVIEw(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {        super(context, attrs, defStyleAttr, defStyleRes);    }    @OverrIDe    public voID scrollTo(int x, int y) {        //do nothing    }}

设置scrollTo什么都不做

在Kotlin:

class NonScrollingTextVIEw : TextVIEw {    constructor(context: Context) : super(context) {}    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}    @TargetAPI(Build.VERSION_CODES.LolliPOP)    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {    }    overrIDe fun scrollTo(x: Int, y: Int) {        //do nothing    }}
总结

以上是内存溢出为你收集整理的android – 如何完全阻止TextView滚动?全部内容,希望文章能够帮你解决android – 如何完全阻止TextView滚动?所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1097551.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存