【问题标题】:Scrollable Textview Not working可滚动的文本视图不起作用
【发布时间】:2016-03-18 21:39:26
【问题描述】:

我正在尝试制作一个可滚动的 TextView,用户可以在其中滚动更新。

我试过了:

XML:

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text=""
    android:scrollbars="vertical"
    android:id="@+id/updateText"
    android:background="#ce000000"
    android:textColor="#FFF"
    android:padding="12dp"
    android:textSize="13sp" />

和代码:

text.setMovementMethod(new ScrollingMovementMethod());
text.setText(updates.get(position).getUpdateText());

但它不能正常工作。

它是滞后的。有时它有效,但大多数时候无效。

谁能帮忙?

【问题讨论】:

  • 你试过把TextView放在ScrollView里面吗?
  • @NoChinDeluxe 是的,我做到了,但它仍然滞后

标签: android android-layout textview scrollview


【解决方案1】:

为您的 TextView 设置以下属性

android:maxLines = "20" // any number
android:scrollbars = "vertical"

还有 setMovementMethod() -

 text.setMovementMethod(new ScrollingMovementMethod());

【讨论】:

  • 我不是说它不工作。但它太慢了,大约需要 5-7 个卷轴,并且有一定的角度才能做 1 个卷轴
【解决方案2】:

我建议你使用一个 ScrollView,然后把它放在这个 TextView 里面。

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text=""
    android:scrollbars="vertical"
    android:id="@+id/updateText"
    android:background="#ce000000"
    android:textColor="#FFF"
    android:padding="12dp"
    android:textSize="13sp" />

【讨论】:

    猜你喜欢
    • 2018-06-18
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    相关资源
    最近更新 更多