android动态添加控件并设置位置样式

		if (mgtEditField!=null){
			if (btnSubmit==null){
				btnSubmit=new Button(this);
				btnSubmit.setBackgroundResource(drawable.udcitem);
				mgtEditField.container.addView(btnSubmit);
				//mgtEditField.container.setBackgroundColor(Color.RED);
				RelativeLayout.LayoutParams lvParams=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
				lvParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
				lvParams.addRule(RelativeLayout.CENTER_VERTICAL);
				
				btnSubmit.setPadding(30, 5, 30, 5);
				float lvfSize=btnSubmit.getTextSize();
				btnSubmit.setTextSize(lvfSize*2);
				btnSubmit.setText("NG");	
				btnSubmit.setTextColor(Color.WHITE);
				btnSubmit.setLayoutParams(lvParams);						
				btnSubmit.setId(BMS312Activity.this.hashCode());
				mgtEditField.scan_label.setVisibility(View.GONE);
				mgtEditField.scan_field.setHint(R.string.LAB311_mgt_hint);										
				lvParams=(LayoutParams) mgtEditField.scan_field.getLayoutParams();
				lvParams.addRule(RelativeLayout.RIGHT_OF,btnSubmit.getId() );					
			}
		}
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。
本站公众号
   欢迎关注本站公众号,获取更多程序园信息
开发小院