Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set layout_margin programmatically? [duplicate]

Tags:

I want to know how to set layout_marginLeft, layout_marginTop, layout_marginBottom programmatically using screen height and width. Please help me.

Thanks Monali

like image 304
Monali Avatar asked Apr 26 '11 09:04

Monali


1 Answers

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); 
like image 170
RoflcoptrException Avatar answered Oct 12 '22 22:10

RoflcoptrException