Android examples for User Interface:View Margin
set View Margins
//package com.java2s; import android.view.View; import android.view.ViewGroup; public class Main { public static void setMargins(View view, int left, int top, int right, int bottom) { ViewGroup.LayoutParams params = view.getLayoutParams(); if (params instanceof ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view .getLayoutParams();/* w ww . jav a2 s . co m*/ marginLayoutParams.setMargins(left, top, right, bottom); view.requestLayout(); } } }