set View Margin Right - Android User Interface

Android examples for User Interface:View Margin

Description

set View Margin Right

Demo Code


//package com.java2s;

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

public class Main {

    public static void setMarginRight(View view, int right) {
        setMargins(view, 0, 0, right, 0);
    }//  w w  w .  jav  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