I am trying to create a layout programmatically where there is one ImageView with two buttons. Now the ImageView will be in the center, and the buttons will be at the bottom of the layout. But I am not able to do it. Here is my code
public class StackView extends RelativeLayout {
....................
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM|Gravity.LEFT);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM|Gravity.RIGHT);
addView(imageview, 0, params);
Button button=new Button(context);
button.setText("left");
button.setGravity(Gravity.START);
addView(button, 1, params1);
Button button1=new Button(context);
button1.setText("right");
button.setGravity(Gravity.END);
addView(button1, 2,params2);
}