package example.withoutxml;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
public class RelativeExample extends Activity implements OnClickListener
{
Button b,b1,b2;
EditText et,et1,et2;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
RelativeLayout rl=new RelativeLayout(this);
rl.setBackgroundResource(R.drawable.day);
//
rl.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
//
LayoutParams.MATCH_PARENT));
b=new Button(this);
b.setWidth(50);
b.setHeight(50);
//b.setBackgroundResource(R.drawable.pinkrose);
b.setText("click here");
b.setGravity(Gravity.BOTTOM);
b.setId(2);
b1=new Button(this);
b1.setWidth(50);
b1.setHeight(50);
b1.setId(4);
b2=new Button(this);
b2.setWidth(50);
b2.setHeight(50);
b2.setId(6);
b2.setText("click me");
et=new EditText(this);
et.setHeight(50);
et.setWidth(50);
et.setId(1);
et1=new EditText(this);
et1.setHeight(50);
et1.setWidth(50);
et1.setId(3);
et2=new EditText(this);
et2.setHeight(50);
et2.setWidth(50);
et2.setId(5);
RelativeLayout.LayoutParams params= new RelativeLayout.LayoutParams
( LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
rl.setLayoutParams(params);
//
params.addRule(RelativeLayout.ALIGN_BOTTOM,1);
//b.setLayoutParams(params);
rl.setGravity(Gravity.FILL_VERTICAL);
//
//
et.setText("text");
//et.setLayoutParams(params);
rl.addView(et);
RelativeLayout.LayoutParams params1= new RelativeLayout.LayoutParams
( LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.BELOW,et.getId());
params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
et1.setLayoutParams(params1);
//rl.addView(et1);
//
RelativeLayout.LayoutParams params7= new RelativeLayout.LayoutParams
// ( LayoutParams.FILL_PARENT,
// LayoutParams.WRAP_CONTENT);
//
params7.addRule(RelativeLayout.ALIGN_LEFT);
//
et1.setLayoutParams(params7);
rl.addView(et1);
RelativeLayout.LayoutParams params2= new RelativeLayout.LayoutParams
( LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.RIGHT_OF,et.getId());
b.setLayoutParams(params2);
rl.addView(b);
RelativeLayout.LayoutParams params3= new RelativeLayout.LayoutParams
( LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params3.addRule(RelativeLayout.BELOW,b.getId());
params3.addRule(RelativeLayout.RIGHT_OF,et1.getId());
b1.setLayoutParams(params3);
// rl.updateViewLayout(b1, params3);
rl.addView(b1);
RelativeLayout.LayoutParams params8= new RelativeLayout.LayoutParams
( LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params8.addRule(RelativeLayout.BELOW,et1.getId());
et2.setLayoutParams(params8);
rl.addView(et2);
//
//
RelativeLayout.LayoutParams params5= new RelativeLayout.LayoutParams
( LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params5.addRule(RelativeLayout.RIGHT_OF,et2.getId());
params5.addRule(RelativeLayout.BELOW,b1.getId());
b2.setLayoutParams(params5);
rl.addView(b2);
b2.setOnClickListener(this);
//
//
rl.set
//et.setLayoutParams(params);
//
rl.addView(et);
//
params.addRule(RelativeLayout.RIGHT_OF,et.getId());
//
b.setLayoutParams(params);
//
//
rl.addView(b);
setContentView(rl);
}
}