Code example for LinearLayout

Methods: addViewsetGravity, setBackgroundColor, setPadding

0
 
		int bottomAndTopPadding = 4;
		int textPadding = 7;
		int iconPadding = 10;
 
		LinearLayout l = new LinearLayout(myContext);
		l.setGravity(Gravity.CENTER_VERTICAL);
 
		l.setPadding(0, bottomAndTopPadding, 0, bottomAndTopPadding);
 
		if (myIcon != null) {
			ImageView i = new ImageView(myContext);
 
			i.setPadding(0, iconPadding, iconPadding, iconPadding);
			i.setImageBitmap(myIcon);
			l.addView(i);
		} else if (myIconId != 0) {
			ImageView i = new ImageView(myContext);
 
			i.setPadding(0, iconPadding, iconPadding, iconPadding);
			i.setImageResource(myIconId);
			l.addView(i);
		} 
 
		TextView t = new TextView(myContext);
		t.setText(myText);
		t.setPadding(textPadding, textPadding, textPadding, textPadding);
		if (myIconId == 0)
			t.setGravity(Gravity.CENTER_HORIZONTAL);
		l.addView(t);
 
		if (getTheme() != null) { 
			getTheme().applyOuter1(l);
			// getTheme().applyOuter1(t); 
		} 
		if (myTextSize != 0)
			t.setTextSize(myTextSize);
		if (myColor != -1) {
			l.setBackgroundColor(myColor);
		} 
 
		return l;
	}