Code example for RelativeLayout.LayoutParams

Methods: addRule, setMargins

0
	 
	@SuppressLint("NewApi") 
	public TextView foodNameText(String foodName, String restaurant) {
		// Setting the RelativeLayout parameters for the Food Name TextView 
		TextView text = new TextView(mContext);
		RelativeLayout.LayoutParams tParams = new RelativeLayout.LayoutParams
				(LayoutParams.WRAP_CONTENT, 50);
		tParams.setMargins(0, 5, 0, 0);
		tParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
		tParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
		text.setLayoutParams(tParams);
		// These are TextView specific parameters (we're done messing with RelativeLayout here) 
		text.setPadding(10, 0, 10, 5);
		text.setBackgroundColor(Color.argb(100, 0, 0, 0));
		text.setTextAlignment(TextView.TEXT_ALIGNMENT_TEXT_END);
		text.setText(Html.fromHtml(foodName + 
				" <i><small><small>from</small></small></i> " +  
				"<small>" + restaurant + "</small>"));
		text.setTextColor(Color.WHITE);                            
		text.setTypeface(Typeface.DEFAULT_BOLD);
		text.setTextSize(25);