android 中动态添加view
2016-01-12 15:19
459 查看
//动态添加view的方法
protected void addView3(LinearLayout ll_notice, ArrayList<String> list) {
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
for(int i=0;i<list.size();i++){
LinearLayout linearLayout = (LinearLayout) LayoutInflater.
from(this).inflate(R.layout.recharge_item_content,null);
TextView tv = (TextView) linearLayout.findViewById(R.id.tv_content);
tv.setText(list.get(i));
tv.setTextSize(16);
tv.setPadding(0,10,0,0);
ll_notice.addView(linearLayout,lp2);
}
}
//布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
protected void addView3(LinearLayout ll_notice, ArrayList<String> list) {
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
for(int i=0;i<list.size();i++){
LinearLayout linearLayout = (LinearLayout) LayoutInflater.
from(this).inflate(R.layout.recharge_item_content,null);
TextView tv = (TextView) linearLayout.findViewById(R.id.tv_content);
tv.setText(list.get(i));
tv.setTextSize(16);
tv.setPadding(0,10,0,0);
ll_notice.addView(linearLayout,lp2);
}
}
//布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
相关文章推荐
- Android中的so挂钩(hook)之Inline hook
- Android利用shape画虚线
- Android BLE蓝牙4.0开发详解
- android 自定义view(二)
- Android安全研究经验谈
- Android安全研究经验谈
- android中popupwindow的点滴
- 安卓开发之百度地图定位
- Fresco介绍 - 一个新的android图片加载库
- android选择图片拍照详解(裁剪-旋转-压缩)
- Android 判断一个url是否有效
- Android如何在java代码中设置margin
- Android Studio上NDK/JNI开发环境问题
- Android属性动画完全解析(三)-Interpolator和ViewPropertyAnimator的用法
- android studio 运行出现 com.android.ide.common.process.ProcessException
- Android 监听输入法隐藏与显示状态切换
- [Andorid开发艺术探索 读书笔记]View的事件体系(二)
- 解决更新Android SDK时出现A folder failed to be renamed or moved办法
- Android中定时执行任务的3种实现方法
- Android Studio 快捷键