Code example for RelativeLayout

Methods: setGravity, addView, setLayoutParams

0
 
		// Hide Titlebar // 
		requestWindowFeature(Window.FEATURE_NO_TITLE);
 
		// Top Header // 
		RelativeLayout j_panel = new RelativeLayout(this);
		j_panel.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT));
		j_panel.setGravity(Gravity.FILL);
		j_panel.setBackground(getResources().getDrawable(R.drawable.back));
		RelativeLayout jMenu = new RelativeLayout(this);
		jMenu.setId(topID);
 
		jMenu.setBackground(getResources().getDrawable(R.drawable.line));
		int jMenuPadding = 6;
		jMenu.setPadding(jMenuPadding, jMenuPadding, jMenuPadding, jMenuPadding);
		RelativeLayout.LayoutParams topParams = new RelativeLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		topParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		j_panel.addView(jMenu, topParams);
 
		int horText = 12;
		j_goButt = new Button(this);
		j_goButt.setId(buttGo);
		j_goButt.setOnClickListener(this);
		j_goButt.setText("Go");
		j_goButt.setTextSize(horText);
		j_goButt.setTypeface(Typeface.create("arial", Typeface.BOLD));
 
		RelativeLayout.LayoutParams papaJ = new RelativeLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		papaJ.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		papaJ.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		jMenu.addView(j_goButt);
		// addr field // 
		j_addr = new EditText(this);
		j_addr.setId(addrID);
		j_addr.setText(j_PageName);
		j_addr.setTextColor(Color.rgb(255, 255, 255));
		horText = 12;
		j_addr.setTextSize(horText);
		j_addr.setTypeface(Typeface.create("arial", Typeface.NORMAL));
 
		RelativeLayout.LayoutParams papaEdit = new RelativeLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		papaEdit.addRule(RelativeLayout.RIGHT_OF, buttGo);
		papaEdit.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		jMenu.addView(j_addr, papaEdit);
 
		// ******* FOOTER ******** // 
		RelativeLayout jMenuBot = new RelativeLayout(this);
		jMenuBot.setId(botID);
		jMenuBot.setBackground(getResources().getDrawable(R.drawable.line));
		jMenuBot.setPadding(jMenuPadding, jMenuPadding, jMenuPadding,
				jMenuPadding);
 
		RelativeLayout.LayoutParams botParams = new RelativeLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		botParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		j_panel.addView(jMenuBot, botParams);
		j_backButt = new Button(this);
		j_backButt.setId(buttBack);
		j_backButt.setOnClickListener(this);
		j_backButt.setText("Back");
		j_backButt.setTextSize(horText);
		j_backButt.setTypeface(Typeface.create("arial", Typeface.BOLD));
 
		RelativeLayout.LayoutParams aka = new RelativeLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		aka.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		aka.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		jMenuBot.addView(j_backButt, aka);
 
		// Forward Button // 
		j_fwdButt = new Button(this);
		j_fwdButt.setId(buttFwd);
		j_fwdButt.setOnClickListener(this);
		j_fwdButt.setText("Fwd");
		j_fwdButt.setTextSize(horText);
		j_fwdButt.setTypeface(Typeface.create("arial", Typeface.BOLD));
		RelativeLayout.LayoutParams aka2 = new RelativeLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		aka2.addRule(RelativeLayout.RIGHT_OF, buttBack);
		aka2.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		jMenuBot.addView(j_fwdButt, aka2);
 
		// Reload (Load) Button // 
		j_loadButt = new Button(this);
		j_loadButt.setId(buttLoad);
		j_loadButt.setOnClickListener(this);
		j_loadButt.setText("Rld");
		j_loadButt.setTextSize(horText);
		j_loadButt.setTypeface(Typeface.create("arial", Typeface.BOLD));
		RelativeLayout.LayoutParams aka3 = new RelativeLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		aka3.addRule(RelativeLayout.RIGHT_OF, buttFwd);
		aka3.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		jMenuBot.addView(j_loadButt, aka3);
 
		// Stop Button // 
		j_stopButt = new Button(this);
		j_stopButt.setId(buttStop);
		j_stopButt.setOnClickListener(this);
		j_stopButt.setText("Stop");
		j_stopButt.setTextSize(horText);
		j_stopButt.setTypeface(Typeface.create("arial", Typeface.BOLD));
		RelativeLayout.LayoutParams aka4 = new RelativeLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		aka4.addRule(RelativeLayout.RIGHT_OF, buttLoad);
		aka4.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		jMenuBot.addView(j_stopButt, aka4);
 
		// Status // 
		j_tv = new TextView(this);
		j_tv.setText("Status");
		j_tv.setTextColor(Color.rgb(255, 255, 255));
		j_tv.setTextSize(horText);
		j_tv.setTypeface(Typeface.create("arial", Typeface.BOLD));
		RelativeLayout.LayoutParams papaTV = new RelativeLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		papaTV.addRule(RelativeLayout.RIGHT_OF, buttStop);
		papaTV.addRule(RelativeLayout.CENTER_VERTICAL);
		jMenuBot.addView(j_tv, papaTV);
 
		// *** WEBVIEW *** // 
		j_web = new WebView(this);
		j_web.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT));
		RelativeLayout.LayoutParams webParams = new RelativeLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		webParams.addRule(RelativeLayout.ABOVE, jMenuBot.getId());
		webParams.addRule(RelativeLayout.BELOW, jMenu.getId());
		j_panel.addView(j_web, webParams);
 
		// Configure webview // 
		j_web.getSettings().setJavaScriptEnabled(true);
		j_web.setWebViewClient(new MyWebViewClient());