Linux 拨号vps windows公众号手机端

android textview滚动怎么实现

lewis 8年前 (2017-03-10) 阅读数 14 #程序编程
文章标签 android

要实现TextView的滚动,可以使用ScrollView或者使用TextView自身的属性来实现。

  1. 使用ScrollView:

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="要显示的文本内容" />
    
    </ScrollView>
    
  2. 使用TextView的属性:

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="要显示的文本内容"
        android:maxLines="10"
        android:scrollbars="vertical" />
    

    在Java代码中,还需要为TextView设置滚动条的监听器:

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

以上两种方法都可以实现TextView的滚动效果,可以根据具体的需求选择适合的方法。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门