Code example for RelativeLayout

Methods: addView, setId, setPadding

0
		super(context, attrs, defStyle);
	} 
 
	@Override 
	protected View onCreateView(final ViewGroup parent) {		
		final RelativeLayout layout = new RelativeLayout(getContext());
		layout.setPadding(15, 5, 15, 5);
 
		 
		 
		//setup title 
		final RelativeLayout.LayoutParams titleparams = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		titleparams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		titleparams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 
		final TextView title = new TextView(getContext());
		title.setText(getTitle());
		title.setTextSize(24);
		title.setTextColor(Color.WHITE);
		title.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
		title.setGravity(Gravity.LEFT);
		title.setLayoutParams(titleparams);
		title.setId(TITLE_ID);
		 
		 
		//setup description 
		final RelativeLayout.LayoutParams descriptionparams = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		descriptionparams.addRule(RelativeLayout.BELOW, title.getId());
//		descriptionparams.addRule(RelativeLayout.LEFT_OF, CHECKBOX_ID); 
		descriptionparams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
 
		description = new TextView(getContext());
		description.setText(summaryOff);
		description.setTextSize(16);
		description.setPadding(10, 0, 0, 0);
		description.setTextColor(Color.GRAY);
		description.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
		description.setGravity(Gravity.LEFT);
		description.setLayoutParams(descriptionparams);
		description.setId(DESCRIPTION_ID);
		 
		 
		 
		//setup slider 
		final RelativeLayout.LayoutParams checkboxparams = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		checkboxparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		checkboxparams.addRule(RelativeLayout.CENTER_VERTICAL);
 
		checkbox = new CheckBox(getContext());
		checkbox.setLayoutParams(checkboxparams);
		checkbox.setOnCheckedChangeListener(this);
		checkbox.setId(CHECKBOX_ID);
		 
		 
 
		layout.addView(title);
		layout.addView(description);
		layout.addView(checkbox);
		layout.setId(android.R.id.widget_frame);
 
		checkService(); 
		 
		return layout;