When I'm in xml
, it only applies the property:
android:margin="15"
I want to apply this same property, but in the source code of java
, how do I do this?
When I'm in xml
, it only applies the property:
android:margin="15"
I want to apply this same property, but in the source code of java
, how do I do this?
Just set the margin in LayoutParams
of View
and ask for a new evaluation of Layout
:
View view = ...
ViewGroup.LayoutParams lp = view.getLayoutParams();
if(lp instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp;
lp.margin = 15;
// Nao esqueca de requisitar o reajuste no layout
view.requestLayout();
}