android 动态添加控件
来源:互联网 发布:gotv倚天屠龙记ts源码 编辑:程序博客网 时间:2024/05/16 14:18
1 控件都是放在容器里面的,也就是各种 layout ,我们动态添加实际就是向这里添加
例如
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/RelativeLayout" ////// android 都是根据 ID 来操作控件等,这个很重要,一般自动生成的文件没有,需要自己添加
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
2 在添加的时候首先要根据 目标layout 的id得到这个容器
代码片段:
my_first_lay = (RelativeLayout) findViewById(R.id.RelativeLayout); // 得到要添加新控件的 layout
Button my_new_button = new Button(MainActivity.this); // 新建一个button
my_new_button.setText("随机生成一个");
RelativeLayout.LayoutParams msl1 = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
msl1.leftMargin = 50;
msl1.topMargin = 100;
my_first_lay.addView(my_new_button); // 添加完成!!
- Android 动态添加控件
- Android--动态添加控件
- Android 动态添加控件
- android --动态添加控件
- android 动态添加控件
- Android 动态代码添加控件
- android 动态设置控件的大小 和 动态添加控件
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- android 在布局中动态添加控件
- Android动态添加控件约束位置
- Android根据布局文件动态添加控件
- android代码中动态添加控件
- android 动态添加控件控制属性问题
- android中怎么动态添加TextView控件
- leetcode LRUCache
- “莫须有”的搜索引擎优化(SEO)迷信
- js中容易出错的地方
- 点击显示菜单 下拉菜单
- “词库门”事件中谷歌搜狐的表现
- android 动态添加控件
- Maven VS Ant
- android 想要弹出另外界面操作步骤
- “赚钱机器”网址导航站的生存之道
- cgs
- 最快速度求两个数组之交集算法(58同城二面笔试题)
- Rest API 开发 学习笔记
- set集合实现排序
- 苹果App Store审核指南中文翻译