
具体方法:
例如你的布局是一个Linearlayout linear上面有一本Button btn1
要删除这个btn1要做的就是 linear.removeView( btn1 )
动态添加也是一样的:
linear.addView( btn2 )
要注意的是,Button btn2 = new Button( context )这时候控件是没有大小的,必须设置控件大小以后添加了才能看到。设置控件大小的方法是view.setLayoutParams()
希望能够帮到你。
jquery文档 *** 作的append()或 appendTo()方法可以在被选元素的结尾插入内容,因此可用于动态创建select控件$("div").append("<select></select>") // 在已经存在的div标签下创建select元素
$("<option></option>").appendTo($("select")) // 为select元素添加option选项
实例演示:动态创建一个含有两个选项——“黑”“白”的select控件,并默认选中“白”这个选项
示例代码如下
创建Html元素
<div class="box">
<span>点击按钮后创建select标签,并默认选中“白”这个选项:</span><br>
<div class="content"></div>
<input type="button" value="创建select标签">
</div>
设置css样式
div.box{width:300pxpadding:20pxmargin:20pxborder:4px dashed #ccc}
div.box span{color:#999font-style:italic}
div.content{width:250pxmargin:10px 0padding:20pxborder:2px solid #ff6666}
select{width:150pxheight:30pxborder:1px solid #6699FF}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)