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.view.View;
import android.view.ViewGroup;

public class Main {
    static public String getViewHierarchy(View v) {
        StringBuilder s = new StringBuilder();
        getViewHierarchy(v, s, 0);
        return s.toString();
    }

    protected static void getViewHierarchy(View v, StringBuilder accumulatedString, int indentation) {
        // append string for the passed in view
        for (int i = 0; i < indentation; ++i) {
            accumulatedString.append("|\t");
        }
        accumulatedString.append(String.format("%s : %d x %d @ (%d, %d)\n", v.getClass().toString(), v.getWidth(),
                v.getHeight(), v.getLeft(), v.getTop()));

        if (v instanceof ViewGroup) {
            ViewGroup g = (ViewGroup) v;
            ++indentation;
            for (int i = 0; i < g.getChildCount(); ++i) {
                getViewHierarchy(g.getChildAt(i), accumulatedString, indentation);
            }
        }
    }
}