Android中的TextView滚动条的设置

经验证, 以下方法可用:

方法一:

a、Xml代码

<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 相应的方法

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

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

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

textView.setScrollbarFadingEnabled(false);


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

<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
a
a
a
a
a
a
a
a
a
a
a
a
a
" />   
</ScrollView>  


原文地址:https://www.cnblogs.com/blogyuan/p/3739635.html