`

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 tv = (TextView)findViewById(R.id.tvCWJ);  
tv.setMovementMethod(ScrollingMovementMethod.getInstance());
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics