Set negative margin on View software

I know how to programmatically set View fields using LinearLayout.LayoutParams and the setMargins(int, int, int, int) method, but how can I put a negative field in the view?

+6
source share
2 answers

Access the layout options for the parent layout and modify them as you wish:

  ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)view.getLayoutParams(); params.topMargin = ...; // etc // or params.setMargins(...); 

After changing the layout, call view.requestLayout() .

+7
source

Using math seems to be a hoax to me enough.

  ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)view.getLayoutParams(); params.topMargin = 100 - 200; // -100 
0
source

Source: https://habr.com/ru/post/952739/


All Articles