private void addCustomViewsWithGravity(List<View> views,int gravity){
  final boolean isRtl=isRtl();
  final int childCount=getChildCount();
  final int absGrav=GravityCompat.getAbsoluteGravity(gravity,getDirectionLayout());
  views.clear();
  if (isRtl) {
    for (int i=childCount - 1; i >= 0; i--) {
      final View child=getChildAt(i);
      final LayoutParams lp=(LayoutParams)child.getLayoutParams();
      if (lp.mViewType == LayoutParams.CUSTOM && shouldLayout(child) && getChildHorizontalGravity(lp.gravity) == absGrav) {
        views.add(child);
      }
    }
  }
 else {
    for (int i=0; i < childCount; i++) {
      final View child=getChildAt(i);
      final LayoutParams lp=(LayoutParams)child.getLayoutParams();
      if (lp.mViewType == LayoutParams.CUSTOM && shouldLayout(child) && getChildHorizontalGravity(lp.gravity) == absGrav) {
        views.add(child);
      }
    }
  }
}

private void addCustomViewsWithGravity ( List < View > views , int gravity ) { final boolean isRtl = isRtl ( ) ; final int childCount = getChildCount ( ) ; final int absGrav = GravityCompat . getAbsoluteGravity ( gravity , getDirectionLayout ( ) ) ; views . clear ( ) ; if ( isRtl ) { for ( int i = childCount - 1 ; i >= 0 ; i -- ) { final View child = getChildAt ( i ) ; final LayoutParams lp = ( LayoutParams ) child . getLayoutParams ( ) ; if ( lp . mViewType == LayoutParams . CUSTOM && shouldLayout ( child ) && getChildHorizontalGravity ( lp . gravity ) == absGrav ) { views . add ( child ) ; } } } else { for ( int i = 0 ; i < childCount ; i ++ ) { final View child = getChildAt ( i ) ; final LayoutParams lp = ( LayoutParams ) child . getLayoutParams ( ) ; if ( lp . mViewType == LayoutParams . CUSTOM && shouldLayout ( child ) && getChildHorizontalGravity ( lp . gravity ) == absGrav ) { views . add ( child ) ; } } } }
prepare a list of non - system child views . if the layout direction is rtl this will be in reverse child order .
