public static int getViewHierarchyMaxDeep(Activity activity) {
View decorView = activity.getWindow().getDecorView();
int height = getDeep(decorView, 1);
Log.e("TAG", activity.getClass().getSimpleName() + " height is:" + height);
return height;
}
private static int getDeep(View view, int curr) {
if (view instanceof ViewGroup) {
ViewGroup parent = (ViewGroup) view;
int childCount = parent.getChildCount();
if (childCount > 0) {
int max = curr + 1;
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int height = getDeep(child, curr + 1);
if (max < height) {
max = height;
}
}
return max;
} else {
return curr;
}
} else {
return curr;
}
}