public static int resolveSizeAndState ( int size , int measureSpec ) { int result = size ; int specMode = MeasureSpec . getMode ( measureSpec ) ; int specSize = MeasureSpec . getSize ( measureSpec ) ; switch ( specMode ) { case MeasureSpec . UNSPECIFIED : result = size ; break ; case MeasureSpec . AT_MOST : if ( specSize < size ) { result = specSize ; } else { result = size ; } break ; case MeasureSpec . EXACTLY : result = specSize ; break ; } return result ; }
Taken and modified from Android Source for API < 11