@ NonNull private OnGlobalLayoutListener createScrollViewChildLayoutListener ( ) { return new OnGlobalLayoutListener ( ) { @ Override public void onGlobalLayout ( ) { View child = scrollView . getChildAt ( 0 ) ; int childHeight = child . getHeight ( ) ; int containerHeight = scrollView . getHeight ( ) - scrollView . getPaddingTop ( ) - scrollView . getPaddingBottom ( ) ; if ( containerHeight > childHeight ) { LinearLayout . LayoutParams layoutParams = ( LinearLayout . LayoutParams ) scrollView . getLayoutParams ( ) ; layoutParams . height = childHeight ; layoutParams . weight = 0 ; scrollView . requestLayout ( ) ; } ViewUtil . removeOnGlobalLayoutListener ( child . getViewTreeObserver ( ) , this ) ; } } ; }
Creates and returns a listener which allows to observe when the child of the dialog s scroll view has been layouted . If the scroll view s height is greater than necessary its height is reduced to match the height of its child .