Access the layout options for the parent layout and modify them as you wish:
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)view.getLayoutParams(); params.topMargin = ...;
After changing the layout, call view.requestLayout() .
source share