I want to know how to set layout_marginLeft, layout_marginTop, layout_marginBottom programmatically using screen height and width. Please help me.
Thanks Monali
Here is an example (adapted from this answer):
LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(10, 20, 30, 40); Button button = new Button(this); button.setText("some text"); layout.addView(button, params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With