在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