Android学习(28) -- 动态创建TextView并展示数据
2016-04-20 05:41
387 查看
我们在编程的时候,除了可以利用布局中的TextView来显示数据,同样我们也可以利用对象来动态创建TextView,并展示数据。
1、创建TextView对象
2、添加数据和属性值
3、把TextView设置为布局的子节点
4、如果需要滚动需要使用ScrollView
布局代码
1、创建TextView对象
2、添加数据和属性值
3、把TextView设置为布局的子节点
4、如果需要滚动需要使用ScrollView
LinearLayout ll = (LinearLayout) findViewById(R.id.lay); //把数据显示至屏幕 for (Person p : personList) { //1.集合中每有一条元素,就new一个textView TextView tv = new TextView(this); //2.把信息设置为文本框的内容 tv.setText(p.toString()); tv.setTextSize(20); //3.把textView设置为线性布局的子节点 ll.addView(tv); }
布局代码
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" > <LinearLayout android:id="@+id/lay" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > </LinearLayout> </ScrollView>
相关文章推荐
- android二维码生成器 艺术二维码
- Android 系统本地推送,只有推送,没有注册系统闹钟推送
- android studio 运行项目gradle出错
- 详解Android接口Interface的使用和意义
- Android解析json数据
- Android数据的四种存储方式----总结
- 一天一个小案例android初阶之页面跳转
- Android Studio 的 10 个你很有可能不知道的技巧
- Android Studio 常用快捷键
- Android开发基础知识点
- Android开发中关于手机振动的问题
- Android Studio 基本使用介绍(一)
- Android Studio 开发调试使用(二)
- Android Studio 构建系统基础(三)
- Android Studio插件安装及使用Genymotion模拟器(四)
- android开发百度地图黑屏闪退现象解决办法
- Android View 绘图流程
- Android View Size
- Android View 滚动机制
- Android 坐标系