Android中的TextView滚动条的设置

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/conconbenben/article/details/25957719

经验证, 以下方法可用:

方法一:

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\na\na\na\na\na\na\na\na\na\na\na\na\na\n" />   
</ScrollView>  


猜你喜欢

转载自blog.csdn.net/conconbenben/article/details/25957719