android代码编写布局和控件
//创建线性linearlayout布局对象
LinearLayout ll = new LinearLayout(this);
//设置linearlayout布局方向
ll.setOrientation(LinearLayout.VERTICAL);
//得到布局或控件高度
int height = LinearLayout.LayoutParams.MATCH_PARENT;
//得到布局或控件宽度
int width = LinearLayout.LayoutParams.MATCH_PARENT;
//给linearlayout布局设置宽高
ll.setLayoutParams(new LinearLayout.LayoutParams(width, height));
//创建TextView控件对象
TextView textView = new TextView(this);
//设置文字
textView.setText("代码写布局");
//设置textview中文字的相对位子
textView.setGravity(Gravity.CENTER);
//把textview控件加入到linearlayout中
ll.addView(textView, new LinearLayout.LayoutParams(width, height));
setContentView(ll);
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。