`
androidssh
  • 浏览: 112363 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

TextView多行本文滚动轻松实现

阅读更多
  Android中我们为了实现文本的滚动可以在ScrollView中嵌入一个TextView,其实TextView自己也可以实现多行滚动的,毕竟ScrollView必须只能有一个直接的子类布局。只要在layout中简单设置几个属性就可以轻松实现

  <TextView 
    android:id="@+id/tvCWJ" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical"   <!--垂直滚动条 -->
    android:singleLine="false"       <!--实现多行 -->
    android:maxLines="15"            <!--最多不超过15行 -->
    android:textColor="#FF0000"
    /> 

   当然我们为了让TextView动起来,还需要用到TextView的setMovementMethod方法设置一个滚动实例,代码如下

   TextView tvAndroid123 = (TextView)findViewById(R.id.tvCWJ);  
tvAndroid123.setMovementMethod(ScrollingMovementMethod.getInstance());   // Android开发网提示相关的可以查看SDK中android.text.method分支了解更多
分享到:
评论
1 楼 mermaid 2010-12-15  
tvAndroid123.setMovementMethod(ScrollingMovementMethod.getInstance());
我用的时候并不是滚动的!

相关推荐

Global site tag (gtag.js) - Google Analytics