Code example for RelativeLayout

Methods: addViewsetGravity, setLayoutParams

0
 
		layout = new LinearLayout(this);
		layout.setLayoutParams(fillParams);
		layout.setOrientation(LinearLayout.VERTICAL);
 
		RelativeLayout cannelLayout = new RelativeLayout(this);
		cannelLayout.setLayoutParams(fillWrapParams);
		// cannelLayout.setBackgroundDrawable(BackGroudSeletor.getdrawble("up_bg2x", 
		// getApplication())); 
		cannelLayout.setGravity(LinearLayout.HORIZONTAL);
 
		Button returnBtn = new Button(this);
		String[] pngArray = { "quxiao_btn2x", "quxiao_btn_hover" };
		// returnBtn.setBackgroundDrawable(BackGroudSeletor.createBgByImageIds(pngArray, 
		// getApplication())); 
		returnBtn.setText("取消");
		wrapParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
		wrapParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		wrapParams.leftMargin = 10;
		wrapParams.topMargin = 10;
		wrapParams.bottomMargin = 10;
 
		returnBtn.setLayoutParams(wrapParams);
		returnBtn.setOnClickListener(new View.OnClickListener() {
 
			@Override 
			public void onClick(View v) {
				// TODO Auto-generated method stub 
				TencentWebAuthActivity.this.finish();
			} 
		}); 
		cannelLayout.addView(returnBtn);
 
		TextView title = new TextView(this);
		title.setText("授权");
		title.setTextColor(Color.WHITE);
		title.setTextSize(24f);
		RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
		titleParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		title.setLayoutParams(titleParams);
		cannelLayout.addView(title);
 
		layout.addView(cannelLayout);
 
		webView = new WebView(this);
		LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,