Java tutorial
//package com.java2s; //License from project: Apache License import android.view.View; import android.view.ViewGroup; public class Main { static int calculateParallaxLayers(View view, boolean recursive) { if (recursive) return calculateParallaxLayersRecursively(view, 0); else return calculateParallaxLayers(view); } private static int calculateParallaxLayers(View view) { if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; return group.getChildCount(); } return 1; } private static int calculateParallaxLayersRecursively(View view, int startCount) { int count = startCount; if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; for (int i = 0; i < group.getChildCount(); i++) { count = calculateParallaxLayersRecursively(group.getChildAt(i), count); } } else { count++; } return count; } }