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

一种是代码写java的layout:

01.RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(80,80);  02.//初始化滚动条控件  03.ScrollView scrollView =new ScrollView(this);  04.scrollView.setScrollContainer(true);  05.scrollView.setFocusable(true);  06.//初始化文字控件  07.TextView textView = new TextView(this);  08.textView.setHorizontallyScrolling(true);  09.textView.setText("哈哈哈,\n哈哈哈");  10.  11.scrollView.addView(textView);  12.main_view.addView(scrollView, param);  

另一种则用layout.xml来实现:

01.<ScrollView   02.           android:layout_width="fill_parent"   03.           android:layout_height="fill_parent"   04.           android:scrollbars="vertical"   05.           android:fadingEdge="vertical">  06.         07.           <TextView  08.                  android:id="@+id/textView"  09.                  android:layout_width="wrap_content"  10.                  android:layout_height="wrap_content"  11.                  android:text="Demo"  12.                  android:textSize="15sp"/>  13.     </ScrollView>  

更多相关文章

  1. [Android(安卓)Pro] Android开发实践:为什么要继承onMeasure()
  2. Android(安卓)WebView和EditText焦点冲突解决
  3. Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布
  4. 使用Weditor(uiautomator2)替换uiautomatorviewer抓取Android控件
  5. Android:listView控件,adapter,以及其他控件的组合
  6. Android(安卓)图片轮播控件
  7. Android(安卓)的 Application 初始化
  8. layout_weight属性图解
  9. Android学习――HorizontalScollview水平滚动控件

随机推荐

  1. 解决API
  2. 对话框的练习(android)
  3. android中的sqlit3数据库进行手机应用软
  4. RelativeLayout布局,以及部分常用属性介绍
  5. android 隐藏虚拟按键
  6. [转]Android中Matrix的pre post set方法
  7. Android 列表数据写入到本地Excel文件(包
  8. Android的res目录
  9. android之通过USB插拔流程来了解android
  10. Android灯光系统(硬件访问服务框架)