TextView自身的滚动条 与 ScrollView的滚动条的差别

  TextView自身也提供了滚动条的设置。ScrollView也提供了滚动条的设置。那么,它们之间有何区别呢?还真的有。

  我是想做一个TextView,然后里边放置一些超链接或者可以点击的ClickableSpan。由于TextView的显示区域有限,内容可能又很多,所以,希望TextView能够出现滚动条。由于TextView自身就可以配置滚动条。于是,这么干:

 

  
  
  
  
  1. <LinearLayout  
  2.         android:orientation="vertical"  
  3.     android:layout_width="fill_parent"   
  4.     android:layout_height="fill_parent">  
  5. ... 
  6.         <TextView android:text=""   
  7.                   android:id="@+id/TextView01"   
  8.                   android:layout_width="fill_parent"   
  9.                   android:layout_height="0dp"  
  10.                   android:scrollbars="vertical"  
  11.                   android:fadeScrollbars="false"  
  12.                   android:layout_weight="2"  
  13.                   >  
  14.                   
  15.         </TextView>  
  16. ...  
  17. </LinearLayout> 

实际在手机上测试,发现,手指一滑动,就会触发内部的超链接或者可点击对象的click事件。这种行为在绝大多数情形下,不是用户所期望的。

改成这样:

  
  
  
  
  1. <LinearLayout  
  2.         android:orientation="vertical" 
  3.         android:layout_width="fill_parent"  
  4.         android:layout_height="fill_parent"> 
  5. ...      
  6.         <ScrollView 
  7.     android:layout_width="fill_parent" 
  8.     android:layout_height="0dp" 
  9.     android:scrollbars="vertical" 
  10.     android:fadeScrollbars="false"  
  11.     android:layout_weight="2"> 
  12.           <TextView android:text=""  
  13.                   android:id="@+id/TextView01"  
  14.                   android:layout_width="fill_parent"  
  15.                   android:layout_height="wrap_content" 
  16.                   > 
  17.                  
  18.           </TextView> 
  19.      </ScrollView> 
  20. ... 
  21. </LinearLayout> 

问题就解决了。滑动时不会触发内部可点击对象的click事件,滑动就是滑动,点击就是点击。

综上,ScrollView是更加普适的滚动方案,TextView自身的滚动在使用时有一定的局限性。

你可能感兴趣的:(textview,区别,滚动条,scrollview)