set View Layout X - Android User Interface

Android examples for User Interface:Layout

Description

set View Layout X

Demo Code


//package com.java2s;

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

import android.widget.RelativeLayout;

public class Main {
    public static void setLayoutX(View view, int x) {
        MarginLayoutParams margin = new MarginLayoutParams(
                view.getLayoutParams());
        margin.setMargins(x, margin.topMargin, x + margin.width,
                margin.bottomMargin);//from  w w w  . j av a 2  s  .  c o  m
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                margin);
        view.setLayoutParams(layoutParams);
    }
}

Related Tutorials