ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)view.getLayoutParams(); params.topMargin = ...; // etc // or params.setMargins(...);
修改布局后,调用view.requestLayout().