在Android 中,

你可以利用排版View的 addView 函数,

将动态产生的View 物件加入到排版View 中,

范例如下 :

main.xml 部分内容

Java 程式码

public class helloWorld extends Activity {    public void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView( R.layout.main );       // 取得LinearLayout 物件      LinearLayout ll = (LinearLayout)findViewById(R.id.viewObj);       // 将TextView 加入到LinearLayout 中      TextView tv = new TextView(this);      tv.setText("Hello World");      ll. addView ( tv );       // 将Button 1 加入到LinearLayout 中      Button b1 = new Button(this);      b1.setText("取消");      ll. addView ( b1 );       // 将Button 2 加入到LinearLayout 中      Button b2 = new Button(this);      b2.setText("确定");      ll. addView ( b2 );       // 从LinearLayout 中移除Button 1      ll. removeView ( b1 );   }}

范例结果 :

原文链接:http://tomkuo139.blogspot.com/2010/01/android-addview-activity-view.html

更多相关文章

  1. 【Android(安卓)开发教程】ListView的总结范例
  2. 【Android(安卓)开发教程】添加ActionBar物件
  3. Android中对TextView中的部分内容的字体样式的设置方法
  4. Google Android(安卓)SDK开发范例大全
  5. 《阿里巴巴Android开发手册》v1.0.1更新,优化部分内容和示例代码
  6. 为什么Android的Adapter中,bindview被调用了多次
  7. 《解析 Google Android(安卓)DSK-智能手机开发范例手册》.(薛显
  8. Android(安卓)基础:SharePreferences知识总结和在“登录”界面的
  9. Google Android(安卓)SDK开发范例------------20141119

随机推荐

  1. 用android做的一个简单的短信发送器(当然
  2. android的Touch事件的消费机制
  3. 如何用手机访问电脑本地 localhost 网页
  4. Android项目管理之数据库升级策略
  5. 关于Android(安卓)Paint.Cap枚举和Paint.
  6. Android游戏编程之音频编程
  7. Android(安卓)编程五要诀:Activity、Servi
  8. Android(安卓)面试那些事之Java基础
  9. 【Android7.1.2源码解析系列】Android编
  10. Android(安卓)绘制多个连续带数字圆圈。