Code example for RelativeLayout

Methods: setGravity, addView, setBackgroundColor, setPadding

0
 
		lastIndex = -1;
 
		setPadding(0, 0, 0, 10);
 
		layout = new RelativeLayout(context);
 
		layout.setBackgroundColor(Color.argb(200, 0, 0, 0));
		layout.setGravity(Gravity.NO_GRAVITY);
		layout.setPadding(4, 2, 4, 2);
 
		RelativeLayout.LayoutParams params = null;
 
		leftImage = new ImageView(context);
		leftImage.setId(100);
		leftImage.setTag("leftButton");
		params = createBaseParams();
		params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		if (Integer.parseInt(Build.VERSION.SDK) > 3) {
			params.addRule(RelativeLayout.CENTER_VERTICAL);
		} 
		params.setMargins(0, 0, 5, 0);
		layout.addView(leftImage, params);
 
		RelativeLayout textLayout = new RelativeLayout(getContext());
		textLayout.setGravity(Gravity.NO_GRAVITY);
		textLayout.setId(101);
 
		title = new TextView(context) {
 
			@Override 
			protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
				super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 
				if (getMeasuredWidth() > 230) {
					setMeasuredDimension(200, getMeasuredHeight());
				} 
			} 
 
		}; 
		title.setId(200);
		title.setTextColor(Color.argb(255, 216,216,216));
		title.setTag("title");
		TiUIHelper.styleText(title, "sans-serif", "15sip", "bold");
		params = createBaseParams();
		params.addRule(RelativeLayout.ALIGN_TOP);
		textLayout.addView(title, params);
 
		snippet = new TextView(context);
		snippet.setId(201);
		snippet.setTextColor(Color.argb(255, 192,192,192));
		snippet.setTag("subtitle");
		TiUIHelper.styleText(snippet, "sans-serif", "10sip", "bold");
		params = createBaseParams();
		params.addRule(RelativeLayout.BELOW, 200);
		textLayout.addView(snippet, params);
 
		params = createBaseParams();
		params.addRule(RelativeLayout.RIGHT_OF, 100);
		params.addRule(RelativeLayout.ALIGN_TOP);
		layout.addView(textLayout, params);
 
		rightImage = new ImageView(context);
		rightImage.setId(103);
		rightImage.setTag("rightButton");
		params = createBaseParams();
		if (Integer.parseInt(Build.VERSION.SDK) > 3) {
			params.addRule(RelativeLayout.CENTER_VERTICAL);
		} 
		params.addRule(RelativeLayout.RIGHT_OF, 101);
		params.setMargins(5, 0, 0, 0);
		layout.addView(rightImage, params);
 
		FrameLayout.LayoutParams fparams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		fparams.gravity = Gravity.NO_GRAVITY;
		addView(layout, fparams);