I want to create an input field with a submit button on the right. Between them, they should cover the width of the screen. I currently have:
LinearLayout row= new LinearLayout(context);
row.setOrientation(HORIZONTAL);
row.setGravity(Gravity.RIGHT);
EditText input = new EditText(context);
Button submit = new Button(context);
submit.setText("Submit");
row.addView(submit);
row.addView(input,LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
myView.addView(row,LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
This leads to the correct distribution of space: the send button takes up as much space as needed, the enter button takes up the remaining space, however they are incorrect (the send button on the left, despite setting the gravity). If you remove gravity and change the order of adding elements to the line, the input field occupies the entire width of the screen, and the submit button is not displayed. What am I doing wrong?
source
share