set View Margin Left - Android User Interface

Android examples for User Interface:View Margin

Description

set View Margin Left

Demo Code


//package com.java2s;

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

public class Main {

    public static void setMarginLeft(View view, int left) {
        setMargins(view, left, 0, 0, 0);
    }/*  w  ww .j  a v a  2  s.  c  o  m*/

    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();
        }
    }
}

Related Tutorials