private static void wrapContentAgain(ViewGroup subTreeRoot, boolean relayoutAllNodes,
                                         int subTreeRootWidthMeasureSpec, int subTreeRootHeightMeasureSpec)
    {
        assert( "main".equals( Thread.currentThread().getName() ) );

        if(subTreeRoot == null)
            return;
        LayoutParams layoutParams = subTreeRoot.getLayoutParams();

        // --- First, we force measure on the subTree
        int widthMeasureSpec 	= subTreeRootWidthMeasureSpec;
        // When LayoutParams.MATCH_PARENT and Width > 0, we apply measured width to avoid getting dimensions too big
        if( layoutParams.width  != LayoutParams.WRAP_CONTENT && subTreeRoot.getWidth() > 0 )
            widthMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getWidth(), MeasureSpec.EXACTLY );
        int heightMeasureSpec 	= subTreeRootHeightMeasureSpec;
        // When LayoutParams.MATCH_PARENT and Height > 0, we apply measured height to avoid getting dimensions too big
        if( layoutParams.height != LayoutParams.WRAP_CONTENT && subTreeRoot.getHeight() > 0 )
            heightMeasureSpec 	=  MeasureSpec.makeMeasureSpec( subTreeRoot.getHeight(), MeasureSpec.EXACTLY );
        // This measure recursively the whole sub-tree
        subTreeRoot.measure( widthMeasureSpec, heightMeasureSpec );

        // --- Then recurse on all children to correct the sizes
        recurseWrapContent( subTreeRoot, relayoutAllNodes );

        // --- RequestLayout to finish properly
        subTreeRoot.requestLayout();
    }
Same as previous, but with given size in case subTreeRoot itself has layout_width or layout_height = "wrap_content"
lib/src/main/java/com/turingtechnologies/materialscrollbar/LayoutWrapContentUpdater.java