I want to make swimming pool with different partitions dynamically. All the partitions is suppose to be buttons. All the positions of the buttons will have coordinates; left,top,right and bottom. How can i setup all the buttons dynamically with java code without having problem with the Layouts. Pool & partitions could look like this Partitions Image. Maybe there is another way to solve it? Canvas?

    ScrollView sv = new ScrollView(this);
    RelativeLayout ll = new RelativeLayout(this);

    Button button = new Button(this);//Creating Button
    button.setPadding(0, 0, 250, 125);
    ll.addView(button);//Finally adding view

    Button button1 = new Button(this);//Creating Button
    button1.setPadding(250, 0, 500, 250);
    ll.addView(button1);//Finally adding view

    Button button2 = new Button(this);//Creating Button
    button2.setPadding(0, 125, 500, 250);
    ll.addView(button2);//Finally adding view

    Button button3 = new Button(this);//Creating Button
    button3.setPadding(0, 250, 500, 500);
    ll.addView(button3);//Finally adding view

1 Answers

The Forgotten Warrior On

If I understood you correctly you want to position one at each corner of the screen, if so you can use something like the following

`RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl); final Button btn = (Button) findViewById(R.id.btn);

LayoutParams lp = (LayoutParams) btn.getLayoutParams();


btn.setLayoutParams(lp); `

you want to duplicate it for each button then change the alignment for each one.