Android中的TextView滚动条的设置

经验证, 如下方法可用:
html

方法一:android

a、Xml代码spa

<TextView 
    android:id="@+id/textview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:singleLine="false" 
    android:maxLines="10" 
    android:scrollbars="vertical" 
    />

b、还须要在代码中设置 TextView 相应的方法code

  1. TextView textView = (TextView)findViewById(R.id.text_view);  htm

  2. textView.setMovementMethod(ScrollingMovementMethod.getInstance());blog

注意若是想要滚动条时刻显示, 必须加上如下语句:ip

textView.setScrollbarFadingEnabled(false);get


Android默认TextView若是在一屏幕显示不下的话,是不会有滚动条的,解决方法是在<TextView>外面添加<ScrollView>标签;class

<ScrollView   
   android:layout_width="fill_parent"   
    android:layout_height="wrap_content" >   
   
   <TextView   
       android:layout_width="fill_parent"   
       android:layout_height="wrap_content"   
        android:textSize="50dp"   
       android:text="a\na\na\na\na\na\na\na\na\na\na\na\na\na\n" />   
</ScrollView>  
相关文章
相关标签/搜索