Code example for RelativeLayout

Methods: addView, addView, setBackgroundColor

0
		super.onCreate(savedInstanceState);
		setContentView(createContentView());
	} 
	 
	private View createContentView() {
		RelativeLayout layout = new RelativeLayout(mContext);
		layout.setBackgroundColor(BG_COLOR);
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
		params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		TextView tip = new TextView(mContext);
		tip.setBackgroundColor(MSG_BG_COLOR);
		tip.setText(TIP_MSG);
		tip.setTextColor(0xFFFFFFFF);
		tip.setPadding(0, 5, 0, 5);
		tip.setGravity(Gravity.CENTER_HORIZONTAL);
		 
		LayoutParams opParams = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
		opParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		TextView opTip = new TextView(mContext);
		opTip.setBackgroundColor(MSG_BG_COLOR);
		opTip.setText(OP_TIP_MSG);
		opTip.setTextSize(12);
		opTip.setTextColor(0xFFFFFFFF);
		opTip.setPadding(0, 5, 0, 5);
		opTip.setGravity(Gravity.CENTER_HORIZONTAL);
		 
		LayoutParams imgParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		imgParams.addRule(RelativeLayout.CENTER_IN_PARENT);
		ImageViewTouch imageView = new ImageViewTouch(mContext);
		imageView.setImageBitmap(mImage);
		imageView.setImageBitmapReset(mImage, true);
		layout.addView(imageView,imgParams);
		layout.addView(tip,params);
		layout.addView(opTip,opParams);
		return layout;
	}