I got these two Buttons I'd like to add to may layout dynamically.
Button settingsButton = new Button(this);
settingsButton.setText("Settings");
View view = findViewById(R.id.content_frame);
int width = view.getWidth() / 5;
int height = view.getHeight() / 5;
settingsButton.setLayoutParams(new LinearLayout.LayoutParams(Math.max(width, height), Math.min(width, height)));
((ViewGroup) view).addView(settingsButton);
Button entryButton = new Button(this);
entryButton.setText("add Entry");
entryButton.setLayoutParams(new LinearLayout.LayoutParams(Math.max(width, height), Math.min(width, height)));
((ViewGroup) view).addView(entryButton);
Now to make the buttons not appear on top of each other I tried giving the second button a margin like:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Math.max(width, height), Math.min(width, height));
params.setMargins(Math.max(width, height), 0, 0, 0);
and then either
((ViewGroup) view).addView(entryButton, params);
or
entryButton.setLayoutParams(params);
((ViewGroup) view).addView(entryButton);
Which both didn't change anything. Any ideas? Thanks!