Reputation: 14435
I know how to set margins of a View
programmatically with LinearLayout.LayoutParams
and the method setMargins(int, int, int, int)
but how can I put a negative margin on a view?
Upvotes: 7
Views: 5811
Reputation: 3419
use this
params.setMargins(0,5-10,0,0);
no
params.setMargins(0,-5,0,0);
Upvotes: 0
Reputation: 4638
Using math seems to trick it enough for me.
ViewGroup.MarginLayoutParams params =
(ViewGroup.MarginLayoutParams)view.getLayoutParams();
params.topMargin = 100 - 200; // -100
Upvotes: 0
Reputation: 152817
Access the layout params for your parent layout and modify them as you like:
ViewGroup.MarginLayoutParams params =
(ViewGroup.MarginLayoutParams)view.getLayoutParams();
params.topMargin = ...; // etc
// or
params.setMargins(...);
After you've modified the layout, call view.requestLayout()
.
Upvotes: 10