Code example for FrameLayout

Methods: measure, setTranslationX

0
        setMeasuredDimension(width, height);
 
        // Measure left pane 
        final int leftPaneWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, mLeftPaneWidth);
        final int leftPaneHeightMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, height);
        mLeftPane.measure(leftPaneWidthMeasureSpec, leftPaneHeightMeasureSpec);
 
        // Measure middle pane 
        final int middlePaneHeightMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, height);
        int middlePaneWidthMeasureSpec;
 
        mMiddlePaneExpandedWidth = width - mLeftPaneWidth;
 
        if (isRightPaneVisible() && mMiddlePaneCollapsible) {
            middlePaneWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, mMiddlePaneCollapsedWidth);
        } else { 
            middlePaneWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, mMiddlePaneExpandedWidth);
        } 
 
        mMiddlePane.measure(middlePaneWidthMeasureSpec, middlePaneHeightMeasureSpec);
 
        // Measure right pane 
        int rightWidthMeasureSpec;
        final int rightHeightMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, height);
 
        if (mMiddlePaneCollapsible) {
            rightWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, width - mMiddlePaneCollapsedWidth);
        } else { 
            rightWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, width);
        } 
 
        final int rightWidth = MeasureSpec.getSize(rightWidthMeasureSpec);
 
        mRightPane.measure(rightWidthMeasureSpec, rightHeightMeasureSpec);
 
        // Just making sure it updates the translations 
        setOffset(mOffset);
    } 
 
    private void setOffset(float offset) {
        mOffset = offset;
 
        invalidate();
 
        final int width = getWidth();
        if (mMiddlePaneCollapsible) {
            final int middlePaneOffset = (int) (-mLeftPaneWidth * offset);
            mLeftPane.setTranslationX(middlePaneOffset);
            mMiddlePane.setTranslationX(middlePaneOffset);
            final int rightPaneTranslation = (int) (-(width - mMiddlePaneCollapsedWidth) * offset);
            mRightPane.setTranslationX(rightPaneTranslation);
        } else { 
            final int viewOffset = (int) (-width * offset);
            mLeftPane.setTranslationX(viewOffset);
            mMiddlePane.setTranslationX(viewOffset);
            mRightPane.setTranslationX(viewOffset);
        } 
    }