I have a parent linear layout.
I need to put three buttons at the bottom of screen horizontally aligned not from XML but through Java code.
Button 1 should be at left of screen
Button 2 should be at bottom of screen
Button 3 should be at right of screen
This is the layout need to be designed:
What I understand is I have to add a relative layout to my parent layout. And some rules for the button.
This is what I tried
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
l=(LinearLayout)findViewById(R.id.mainl);
rl=new RelativeLayout(this);
b1=new Button(this);
b2=new Button(this);
b3=new Button(this);
b1.setText("Button 1");
b2.setText("Button 2");
b3.setText("Button 3");
rl.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rl.addView(b1);
rl.addView(b2);
rl.addView(b3);
l.addView(rl);
}
And also the buttons are not coming at bottom. They are coming at top of screen.
Activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>