在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. Word基础
  2. 轻量级Lua IDE ZeroBrane Studio 的使用技巧和汉化
  3. IOS - ARC改为非ARC
  4. MUI - 上拉刷新/下拉加载
  5. NSNotificationCenter
  6. 理解 B*tree index内部结构
  7. 使用Discuz!自带参数防御CC攻击以及原理,修改Discuz X 开启防CC攻击后,不影响搜索引擎收录的方法
  8. Newtonsoft.Json 时区差解决方法
  9. Flex组件的生命周期
  10. linux_inode 和 block
  11. Go-For Range 性能研究
  12. Azure中block和Page的比较 Azure: Did You Know? Block vs Page Blobs
  13. linux固定IP
  14. 网络请求(I)
  15. Jenkins安装时Web页面报错提示离线安装
  16. Windows server 2012 R2 解决“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同
  17. 使用position:relative制作下边框下的小三角
  18. PostgreSQL9.3安装tds_fdw扩展
  19. Activiti进阶(二)——部署流程资源的三种方式
  20. 简说mvc路由

热门文章

  1. 字符串聚合技术(String Aggregation Techniques)
  2. C++结构体中sizeof(1)
  3. Inno setup卸载前退出进程、删除文件夹
  4. [Poco库]使用经验
  5. oracle中的初始化参数文件
  6. Android 开源控件系列_1
  7. web 之MVC
  8. 【Chromium中文文档】线程
  9. python中实现多线程的几种方式
  10. 用实例给新手讲解RSA加密算法