TextView滚动功能的实现

来源:互联网 发布:windows上的弹球游戏 编辑:程序博客网 时间:2024/05/22 14:40

转自 http://www.apkstory.com/development/textview-scroll-function.html


滚动条大家肯定不陌生的,当然这里说的不是ScrollView,在很多的时候需要一个TextView来显示很多内容,但是内容太多了超过了TextView的显示范围,这个时候就需要TextView里面的内容滚动起来。首先看下布局文件:

view plaincopy to clipboardprint?
  1. <TextView  
  2. android:id="@+id/reportContent"  
  3. android:layout_width="fill_parent"  
  4. android:layout_height="wrap_content"  
  5. android:maxLines="20"  
  6. android:scrollbars="vertical"  
  7. android:singleLine="false" />  

当内容超过了20行的时候就会出现滚动条了,这样才符合上面的描述,但是即便布局文件这样设置了相关属性,但是在显示的时候仍然达不到我们的要求,因为我们肯定需要把没有显示出来的内容通过滚动能够显示出来,这就需要在代码里面设置TextView的相关属性来,代码如下:

view plaincopy to clipboardprint?
  1. reportContent = (TextView)findViewById(R.id.reportContent);  
  2. //如果reportContent内容太多了的话,我们需要让其滚动起来,  
  3. //具体可以查看SDK中android.text.method了解更多,代码如下:  
  4. reportContent.setMovementMethod(ScrollingMovementMethod.getInstance()) ;  

  


原创粉丝点击