public class MainActivity extends Activity { RelativeLayout rl= (RelativeLayout) findViewById(R.id.imageView5);; ImageView iv; RelativeLayout.LayoutParams params; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); onClickBtn(); int yellow_iv_id = 123; // Some arbitrary ID value. iv = new ImageView(this); iv.setId(yellow_iv_id); iv.setBackgroundColor(Color.YELLOW); params = new RelativeLayout.LayoutParams(30, 40); params.leftMargin = 50; params.topMargin = 60; rl.addView(iv, params); iv = new ImageView(this); iv.setBackgroundColor(Color.RED); params = new RelativeLayout.LayoutParams(30, 40); params.leftMargin = 80; params.topMargin = 90; // This line defines how params.leftMargin and params.topMargin are interpreted. // In this case, "<80,90>" means <80,90> to the right of the yellow ImageView. params.addRule(RelativeLayout.RIGHT_OF, yellow_iv_id); rl.addView(iv, params); } /* public void onClickBtn(){ Button btn1=(Button)findViewById(R.id.button1); btn1.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { TextView textView=(TextView)findViewById(R.id.textView1); textView.setText("Go to postion A"); } }); }*/ }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)