protected void layoutMajorAxis(int targetSpan,int axis,int[] offsets,int[] spans){
  long preferred=0;
  int n=getViewCount();
  for (int i=0; i < n; i++) {
    View v=getView(i);
    spans[i]=(int)v.getPreferredSpan(axis);
    preferred+=spans[i];
  }
  long desiredAdjustment=targetSpan - preferred;
  float adjustmentFactor=0.0f;
  int[] diffs=null;
  if (desiredAdjustment != 0) {
    long totalSpan=0;
    diffs=new int[n];
    for (int i=0; i < n; i++) {
      View v=getView(i);
      int tmp;
      if (desiredAdjustment < 0) {
        tmp=(int)v.getMinimumSpan(axis);
        diffs[i]=spans[i] - tmp;
      }
 else {
        tmp=(int)v.getMaximumSpan(axis);
        diffs[i]=tmp - spans[i];
      }
      totalSpan+=tmp;
    }
    float maximumAdjustment=Math.abs(totalSpan - preferred);
    adjustmentFactor=desiredAdjustment / maximumAdjustment;
    adjustmentFactor=Math.min(adjustmentFactor,1.0f);
    adjustmentFactor=Math.max(adjustmentFactor,-1.0f);
  }
  int totalOffset=0;
  for (int i=0; i < n; i++) {
    offsets[i]=totalOffset;
    if (desiredAdjustment != 0) {
      float adjF=adjustmentFactor * diffs[i];
      spans[i]+=Math.round(adjF);
    }
    totalOffset=(int)Math.min((long)totalOffset + (long)spans[i],Integer.MAX_VALUE);
  }
}

protected void layoutMajorAxis ( int targetSpan , int axis , int [ ] offsets , int [ ] spans ) { long preferred = 0 ; int n = getViewCount ( ) ; for ( int i = 0 ; i < n ; i ++ ) { View v = getView ( i ) ; spans [ i ] = ( int ) v . getPreferredSpan ( axis ) ; preferred += spans [ i ] ; } long desiredAdjustment = targetSpan - preferred ; float adjustmentFactor = 0.0f ; int [ ] diffs = null ; if ( desiredAdjustment != 0 ) { long totalSpan = 0 ; diffs = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { View v = getView ( i ) ; int tmp ; if ( desiredAdjustment < 0 ) { tmp = ( int ) v . getMinimumSpan ( axis ) ; diffs [ i ] = spans [ i ] - tmp ; } else { tmp = ( int ) v . getMaximumSpan ( axis ) ; diffs [ i ] = tmp - spans [ i ] ; } totalSpan += tmp ; } float maximumAdjustment = Math . abs ( totalSpan - preferred ) ; adjustmentFactor = desiredAdjustment / maximumAdjustment ; adjustmentFactor = Math . min ( adjustmentFactor , 1.0f ) ; adjustmentFactor = Math . max ( adjustmentFactor , - 1.0f ) ; } int totalOffset = 0 ; for ( int i = 0 ; i < n ; i ++ ) { offsets [ i ] = totalOffset ; if ( desiredAdjustment != 0 ) { float adjF = adjustmentFactor * diffs [ i ] ; spans [ i ] += Math . round ( adjF ) ; } totalOffset = ( int ) Math . min ( ( long ) totalOffset + ( long ) spans [ i ] , Integer . MAX_VALUE ) ; } }
performs layout for the major axis of the box ( i . e . the axis that it represents ) . the results of the layout ( the offset and span for each children ) are placed in the given arrays which represent the allocations to the children along the major axis .
