Code example for RelativeLayout

Methods: setGravity, addView, setId, setLayoutParams

0
	private View generateContentView() {
		// 创建一个垂直的线性布局(整体内容) 
		viewFlipper = new ViewFlipper(this);
		viewFlipper.setId(calLayoutID);
		 
		mainLayout = new RelativeLayout(this); // 创建一个垂直的线性布局(整体内容)
		RelativeLayout.LayoutParams params_main = new RelativeLayout.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		mainLayout.setLayoutParams(params_main);
		mainLayout.setId(mainLayoutID);
		mainLayout.setGravity(Gravity.CENTER_HORIZONTAL);
 
		calStartDate = getCalendarStartDate();
 
		setTitleGirdView(); 
		RelativeLayout.LayoutParams params_cal_title = new RelativeLayout.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		params_cal_title.addRule(RelativeLayout.BELOW, titleLayoutID);
		mainLayout.addView(title_gView, params_cal_title);
 
		CreateGirdView(); 
 
		RelativeLayout.LayoutParams params_cal = new RelativeLayout.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		params_cal.addRule(RelativeLayout.BELOW, caltitleLayoutID);
		mainLayout.addView(viewFlipper, params_cal);
		 
		LinearLayout br = new LinearLayout(this);
		RelativeLayout.LayoutParams params_br = new RelativeLayout.LayoutParams(
				LayoutParams.FILL_PARENT, 1);
		params_br.addRule(RelativeLayout.BELOW, calLayoutID);
		br.setBackgroundColor(getResources().getColor(R.color.calendar_background));
		mainLayout.addView(br, params_br);
 
		return mainLayout;
 
	} 
 
Connect your IDE to all the code out there  Get Codota for Java