Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static void wrapView(View view, ViewGroup wrapper) {
        final ViewParent parent = view.getParent();

        if (parent != null && parent instanceof ViewGroup) {
            final ViewGroup parentViewGroup = (ViewGroup) parent;

            // Wrapper should have same layout params as the previous view had
            ViewGroup.LayoutParams previousLayoutParams = view.getLayoutParams();

            final int indexOfChild = parentViewGroup.indexOfChild(view);
            parentViewGroup.removeView(view);

            parentViewGroup.addView(wrapper, indexOfChild, previousLayoutParams);
        }

        wrapper.addView(view);
    }
}