Code example for RelativeLayout.LayoutParams

Methods: addRule, setMargins

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