Android TextView文字超出一屏不能显示其它的文字 解决方案

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

一种是代码写java的layout:

RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(80,80);
//初始化滚动条控件
ScrollView scrollView =new ScrollView(this);
scrollView.setScrollContainer(true);
scrollView.setFocusable(true);
//初始化文字控件
TextView textView = new TextView(this);
textView.setHorizontallyScrolling(true);
textView.setText("哈哈哈,\n哈哈哈");

scrollView.addView(textView);
main_view.addView(scrollView, param);
另一种则用layout.xml来实现:

<ScrollView 
           android:layout_width="fill_parent" 
           android:layout_height="fill_parent" 
           android:scrollbars="vertical" 
           android:fadingEdge="vertical">
       
           <TextView
                  android:id="@+id/textView"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Demo"
                  android:textSize="15sp"/>
     </ScrollView>

参考链接: http://norety.iteye.com/blog/638475

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值