【问题标题】:How to create scrollable Textview in android如何在android中创建可滚动的Textview
【发布时间】:2015-08-14 06:47:47
【问题描述】:

我有一个要求,我需要在 android 中创建一个可滚动的 textview。
例如,我有一个需要在 TextView 中显示的长文本。
最初它应该显示带有超链接“showmore”的部分文本。单击“showmore”链接应显示滚动整个布局的完整文本。


谁能帮我在Android中创建这种类型的标签(“TextView”)


提前致谢

【问题讨论】:

标签: android android-widget


【解决方案1】:

n 你的 XML 布局文件:

<TextView
    android:id="@+id/text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:text="@string/hello" />

在您的 Java 类文件中:

TextView mTextView = (TextView) findViewById(R.id.text_view);
mTextView.setMovementMethod(new ScrollingMovementMethod());

【讨论】:

    【解决方案2】:

    如果你愿意,你可以添加一个包裹你的 TextView 的 ScrollView:

    <ScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="vertical"
      android:padding="10dp"
      android:layout_margin="5dp">
        <TextView
          android:id="@+id/textView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textSize="18sp"/>
      </ScrollView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-15
      • 2011-04-22
      • 2013-05-25
      • 2015-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多