package com.example.codelayout;

import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.Menu;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		RelativeLayout mLayout = new RelativeLayout(this);
		TextView mView = new TextView(this);
		mView.setId(1);
		mView.setText("MYBOOK");
		RelativeLayout.LayoutParams mViewparam = new RelativeLayout.LayoutParams (
			    RelativeLayout.LayoutParams.WRAP_CONTENT,
			    RelativeLayout.LayoutParams.WRAP_CONTENT);
		mViewparam.addRule(RelativeLayout.CENTER_HORIZONTAL);
		     	mLayout.addView(mView,mViewparam); // or mView.setLayoutParams(mViewparam);
		Button btn = new Button(this);
		btn.setId(2);
		btn.setText("BUTTON");
		RelativeLayout.LayoutParams btnparam = new RelativeLayout.LayoutParams (
			    RelativeLayout.LayoutParams.WRAP_CONTENT,
			    RelativeLayout.LayoutParams.WRAP_CONTENT);
		btnparam.addRule(RelativeLayout.ALIGN_LEFT);
		btnparam.addRule(RelativeLayout.CENTER_VERTICAL);
		mLayout.addView(btn,btnparam);
		mViewparam.addRule(RelativeLayout.BELOW, btn.getId());
		mViewparam. setMargins(0 , 80 , 0 , 0);
		setContentView(mLayout);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
