here is a function that returns the number of visible children in a ViewGroup, for example LinearLayout, RelativeLayout, ScrollView, .. etc
private int countVisible(ViewGroup myLayout) { if(myLayout==null) return 0; int count = 0; for(int i=0;i<myLayout.getChildCount();i++) { if(myLayout.getChildAt(i).getVisibility()==View.VISIBLE) count++; } return count; }
source share