动态添加控件
来源:互联网 发布:淘宝劵 编辑:程序博客网 时间:2024/05/02 04:43
线性布局LinearLayout
xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > </LinearLayout>
activity:
public class ButtonTestActivity extends Activity { /** Called when the activity is first created. */private LinearLayout myLayout; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myLayout = (LinearLayout)findViewById(R.id.myLayout); //动态添加7行8列按钮 for(int j=0; j<7; j++){ LinearLayout childLayout = new LinearLayout(this); childLayout.setOrientation(LinearLayout.HORIZONTAL);//子线性布局内部为 水平排列 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,0, 1);//垂直方向上按权重来设置大小 myLayout.addView(childLayout, params); for(int i=0;i<8; i++){ Button button = new Button(this); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(0, LayoutParams.FILL_PARENT, 1);//水平方向上按权重来设置大小 childLayout.addView(button, param); } } }}
绝对布局AbsoluteLayout
AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(20,20, 40, 40);aLayout.addView(nButton, params);//添加button在屏幕上
- 动态添加控件
- 动态添加web控件
- 动态添加控件
- Web动态添加控件
- 动态添加用户控件
- 动态添加控件事件
- 动态控件添加问题
- 动态添加web控件
- 动态添加控件
- 动态添加控件TextBox2
- 动态添加控件
- HTML 动态添加控件
- 动态添加控件
- JavaScript 动态添加控件
- 动态添加控件注意事项
- 动态添加控件
- 动态添加控件
- c 动态添加控件
- 黑马程序员~多线程小述
- Visual Studio调试多线程应用程序
- printf(&unix["\021%siz\012\0"].....
- oracle 10G jobs运行报错 sys.dbms_ijob sys.dbms_jos
- 域名与IP地址及其映射
- 动态添加控件
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- 【QC开发相关】解决无法创建TDConnection(OTAClient.dll中提供)对象的问题(错误0x800703e6)
- hdu 1025 Constructing Roads In JGShining's Kingdom【即求最长上升子序列】
- JSP内置对象
- 【javaWeb】Struts 2导出excel文件
- 为产品赋予人格 - 情感化设计的组成要素及实践案例
- oracle中的connect by prior ... start with 数据库的递归算法
- glibc ptmalloc中的宏操作