Both pieces are to place two objects near each other with a fixed size for one of them
Piece one. Works as supposed: dynamically filled scrollView takes all the space possible above the keyboard
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
root.addView(keyboardView, params);
params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.ABOVE, keyboardView.getId());
root.addView(scrollView, params);
Piece two. Supposed to place a button on the right and an editText taking the rest of the place to the left of the button. Instead, the editText ignores the button and takes the whole screen width, so the button is under it
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
container.addView(deleteButton, params);
params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.LEFT_OF, deleteButton.getId());
container.addView(editText, params);
Piece two remade in XML. For some reason, working as needed
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Delete"
android:id="@+id/item_deleteButton"
android:layout_alignParentRight="true"
android:layout_alignBottom="@+id/item_editText" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/item_editText"
android:layout_toLeftOf="@+id/item_deleteButton" />
</RelativeLayout>