Convenience version of set View Margins - Android User Interface

Android examples for User Interface:View Margin

Description

Convenience version of set View Margins

Demo Code


//package com.java2s;

import android.view.View;
import android.view.ViewGroup;

public class Main {
    /** Convenience version of setViewMargins(View view, int left, int top, int right, int bottom) */
    public static void setViewMargins(View view, int margin) {
        setViewMargins(view, margin, margin, margin, margin);
    }//from  w  w w  . j  a  v a2s  .co  m

    /** Convenience version of setViewMargins(View view, int left, int top, int right, int bottom) */
    public static void setViewMargins(View view, int vertical,
            int horizontal) {
        setViewMargins(view, horizontal, vertical, horizontal, vertical);
    }

    /** Sets the margins for a view in a ViewGroup of type LinearLayout, RelativeLayout, or FrameLayout */
    public static void setViewMargins(View view, int left, int top,
            int right, int bottom) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view
                .getLayoutParams();
        params.setMargins(left, top, right, bottom);
    }
}

Related Tutorials