在android上面让TextView 过多的文字实现有滚动条 scrollview

 

在android上面让TextView过多的文字实现有滚动条,之前想简单了以为设置TextView的属性就可以实现,结果还是需要ScrollView配合使用,才能达到滚动条的效果有两种方式实现,

一种是代码写java的layout

Java代码

  1. RelativeLayout.LayoutParams param new RelativeLayout.LayoutParams(80,80);  
  2. //初始化滚动条控件  
  3. ScrollView scrollView =new ScrollView(this);  
  4. scrollView.setScrollContainer(true);  
  5. scrollView.setFocusable(true);  
  6. //初始化文字控件  
  7. TextView textView new TextView(this);  
  8. textView.setHorizontallyScrolling(true);  
  9. textView.setText("走情感路线,哈哈哈,n 走情感路线,哈哈哈");  
  10.   
  11. scrollView.addView(textView);  
  12. main_view.addView(scrollView, param);  
 

另一种则用layout.xml来实现

 

Xml代码
  1. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"  
  2.         android:layout_width="fill_parent" android:layout_height="fill_parent"   
  3. android:scrollbars="vertical" android:fadingEdge="vertical">  
  4.         <TextView android:layout_width="fill_parent" android:layout_height="wrap_content"   
  5. android:id="@+id/text_view" android:textColor="#071907" android:paddingTop="5dip" />  
  6. </ScrollView> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值