Adding Margins To Button Object Programatically
Need to set left margin to a button object programatically. This is the code segment: RelativeLayout rl = (RelativeLayout) findViewById(R.id.for_button); MarginLayoutParams ml = ne
Solution 1:
Alright, I'm gonna give this a shot IronBlossom; this is how I do it and I hope it works:
LinearLayout myLinearLayout = (LinearLayout)findViewById(R.id.my_linear_layout);
Button myButton = new Button(this);
// more myButton attribute setting here like text etc //
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
params.setMargins(5,0,0,0);
myLinearLayout.addView(myButton, params);
best,
-serkan
Post a Comment for "Adding Margins To Button Object Programatically"