Android examples for User Interface:View Margin
set View Margin Top
//package com.java2s; import android.view.View; import android.view.ViewGroup; public class Main { public static void setMarginTop(View view, int top) { setMargins(view, 0, top, 0, 0);//from w w w.j ava 2s .c om } public static void setMargins(View view, int left, int top, int right, int bottom) { if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view .getLayoutParams(); p.setMargins(left, top, right, bottom); view.requestLayout(); } } }