Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.widget.RelativeLayout;

public class Main {
    public static RelativeLayout.LayoutParams getViewPositionParams(String alignment, int offsetX, int offsetY,
            int w, int h, int below) {

        // create a layout params
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(w, h);

        // alignment vertical rule
        if (alignment.contains("top")) {
            params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        } else if (alignment.contains("bottom")) {
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        } else {
            params.addRule(RelativeLayout.CENTER_VERTICAL);
        }

        // alignment horizontal rule
        if (alignment.contains("left")) {
            params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        } else if (alignment.contains("right")) {
            params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        } else {
            params.addRule(RelativeLayout.CENTER_HORIZONTAL);
        }

        // set below
        if (below > 0) {
            params.addRule(RelativeLayout.BELOW, below);
        }

        return params;
    }
}