Example usage for android.view Gravity HORIZONTAL_GRAVITY_MASK

List of usage examples for android.view Gravity HORIZONTAL_GRAVITY_MASK

Introduction

In this page you can find the example usage for android.view Gravity HORIZONTAL_GRAVITY_MASK.

Prototype

int HORIZONTAL_GRAVITY_MASK

To view the source code for android.view Gravity HORIZONTAL_GRAVITY_MASK.

Click Source Link

Document

Binary mask to get the absolute horizontal gravity of a gravity.

Usage

From source file:com.kyo.fitssystemwindows.FitsSystemWindowsFrameLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final boolean applyInsets = lastInsets != null && ViewCompat.getFitsSystemWindows(this);
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }//  w  w  w.j  a  va  2 s.co  m

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (lp.gravity == -1) {
            lp.gravity = DEFAULT_CHILD_GRAVITY;
        }

        if (applyInsets) {
            int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection);

            if (cgrav == -1) {
                cgrav = DEFAULT_CHILD_GRAVITY;
            } else {
                if ((cgrav & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
                    cgrav = cgrav | Gravity.TOP;
                }
                if ((cgrav & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
                    cgrav = cgrav | (layoutDirection == LAYOUT_DIRECTION_LTR ? Gravity.LEFT : Gravity.RIGHT);
                }
            }

            if (ViewCompat.getFitsSystemWindows(child)) {
                final int l = child.getPaddingLeft();
                final int t = child.getPaddingTop();
                final int r = child.getPaddingRight();
                final int b = child.getPaddingBottom();
                IMPL.dispatchChildInsets(child, lp, cgrav, lastInsets);
                child.setPadding(l, t, r, b);
            } else {
                IMPL.applyMarginInsets(lp, cgrav, lastInsets);
                lp.leftMargin += lp.leftMargin2;
                lp.topMargin += lp.topMargin2;
                lp.rightMargin += lp.rightMargin2;
                lp.bottomMargin += lp.bottomMargin2;
            }
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE || ViewCompat.getFitsSystemWindows(child)) {
            continue;
        }
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        lp.leftMargin -= lp.leftMargin2;
        lp.topMargin -= lp.topMargin2;
        lp.rightMargin -= lp.rightMargin2;
        lp.bottomMargin -= lp.bottomMargin2;
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java

/**
 * Describes how the selected item view is positioned. Currently only the horizontal component
 * is used. The default is determined by the current theme.
 *
 * @param gravity See {@link android.view.Gravity}
 *
 * @attr ref android.R.styleable#Spinner_gravity
 *//*from  ww  w . j  a  v  a2s  .co  m*/
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.LEFT;
        }
        mGravity = gravity;
        requestLayout();
    }
}

From source file:com.iangclifton.android.floatlabel.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }/* ww  w  .j a v a 2  s  .c  o m*/

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = parentRight - width - lp.rightMargin;
            break;
        case Gravity.LEFT:
        default:
            childLeft = parentLeft + lp.leftMargin;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:com.vinfotech.widget.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }//  w w  w .  ja v a2  s . c o m

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = parentRight - width - lp.rightMargin;
            break;
        case Gravity.LEFT:

        default:
            childLeft = parentLeft + lp.leftMargin;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:io.plaidapp.ui.widget.FabOverlapTextView.java

private void recompute(int width) {
    if (text != null) {
        // work out the top padding and line height to align text to a 4dp grid
        float fourDip = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
                getResources().getDisplayMetrics());

        // Ensure that the first line's baselines sits on 4dp grid by setting the top padding
        Paint.FontMetricsInt fm = paint.getFontMetricsInt();
        int gridAlignedTopPadding = (int) (fourDip
                * (float) Math.ceil((topPaddingHint + Math.abs(fm.ascent)) / fourDip)
                - Math.ceil(Math.abs(fm.ascent)));
        setPadding(getPaddingLeft(), gridAlignedTopPadding, getPaddingRight(), getPaddingBottom());

        // Ensures line height is a multiple of 4dp
        int fontHeight = Math.abs(fm.ascent - fm.descent) + fm.leading;
        int baselineAlignedLineHeight = (int) (fourDip * (float) Math.ceil(lineHeightHint / fourDip));

        // before we can workout indents we need to know how many lines of text there are;
        // so we need to create a temporary layout :(
        layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                .setLineSpacing(baselineAlignedLineHeight - fontHeight, 1f).setBreakStrategy(breakStrategy)
                .build();//  w ww .  j  a v  a  2 s.  c om
        int preIndentedLineCount = layout.getLineCount();

        // now we can calculate the indents required for the given fab gravity
        boolean gravityTop = (fabGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP;
        boolean gravityLeft = (fabGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.LEFT;
        // we want to iterate forward/backward over the lines depending on whether the fab
        // overlap vertical gravity is top/bottom
        int currentLine = gravityTop ? 0 : preIndentedLineCount - 1;
        int remainingHeightOverlap = fabOverlapHeight - (gravityTop ? getPaddingTop() : getPaddingBottom());
        int[] leftIndents = new int[preIndentedLineCount];
        int[] rightIndents = new int[preIndentedLineCount];
        do {
            if (remainingHeightOverlap > 0) {
                // still have overlap height to consume, set the appropriate indent
                leftIndents[currentLine] = gravityLeft ? fabOverlapWidth : 0;
                rightIndents[currentLine] = gravityLeft ? 0 : fabOverlapWidth;
                remainingHeightOverlap -= baselineAlignedLineHeight;
            } else {
                // have consumed the overlap height: no indent
                leftIndents[currentLine] = 0;
                rightIndents[currentLine] = 0;
            }
            if (gravityTop) { // iterate forward over the lines
                currentLine++;
            } else { // iterate backward over the lines
                currentLine--;
            }
        } while (gravityTop ? currentLine < preIndentedLineCount : currentLine >= 0);

        // now that we know the indents, create the actual layout
        layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                .setLineSpacing(baselineAlignedLineHeight - fontHeight, 1f)
                .setIndents(leftIndents, rightIndents).setBreakStrategy(breakStrategy).build();
    }
}

From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java

private void recompute(int width) {
    if (text != null) {
        // work out the top padding and line height to align text to a 4dp grid
        final float fourDip = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
                getResources().getDisplayMetrics());

        // ensure that the first line's baselines sits on 4dp grid by setting the top padding
        final Paint.FontMetricsInt fm = paint.getFontMetricsInt();
        final int gridAlignedTopPadding = (int) (fourDip
                * (float) Math.ceil((unalignedTopPadding + Math.abs(fm.ascent)) / fourDip)
                - Math.ceil(Math.abs(fm.ascent)));
        super.setPadding(getPaddingLeft(), gridAlignedTopPadding, getPaddingTop(), getPaddingBottom());

        // ensures line height is a multiple of 4dp
        final int fontHeight = Math.abs(fm.ascent - fm.descent) + fm.leading;
        final int baselineAlignedLineHeight = (int) (fourDip * (float) Math.ceil(lineHeightHint / fourDip));

        // before we can workout indents we need to know how many lines of text there are;
        // so we need to create a temporary layout :(
        layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                .setLineSpacing(baselineAlignedLineHeight - fontHeight, 1f).setBreakStrategy(breakStrategy)
                .build();//from  w ww  . ja  va2s . c  o  m
        final int preIndentedLineCount = layout.getLineCount();

        // now we can calculate the indents required for the given fab gravity
        final boolean gravityTop = (fabGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP;
        final boolean gravityLeft = (fabGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.LEFT;
        // we want to iterate forward/backward over the lines depending on whether the fab
        // overlap vertical gravity is top/bottom
        int currentLine = gravityTop ? 0 : preIndentedLineCount - 1;
        int remainingHeightOverlap = fabOverlapHeight - (gravityTop ? getPaddingTop() : getPaddingBottom());
        final int[] leftIndents = new int[preIndentedLineCount];
        final int[] rightIndents = new int[preIndentedLineCount];
        do {
            if (remainingHeightOverlap > 0) {
                // still have overlap height to consume, set the appropriate indent
                leftIndents[currentLine] = gravityLeft ? fabOverlapWidth : 0;
                rightIndents[currentLine] = gravityLeft ? 0 : fabOverlapWidth;
                remainingHeightOverlap -= baselineAlignedLineHeight;
            } else {
                // have consumed the overlap height: no indent
                leftIndents[currentLine] = 0;
                rightIndents[currentLine] = 0;
            }
            if (gravityTop) { // iterate forward over the lines
                currentLine++;
            } else { // iterate backward over the lines
                currentLine--;
            }
        } while (gravityTop ? currentLine < preIndentedLineCount : currentLine >= 0);

        // now that we know the indents, create the actual layout
        layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                .setLineSpacing(baselineAlignedLineHeight - fontHeight, 1f)
                .setIndents(leftIndents, rightIndents).setBreakStrategy(breakStrategy).build();

        // ensure that the view's height sits on the grid (as we've changed padding etc).
        final int height = getPaddingTop() + layout.getHeight() + getPaddingBottom();
        final float overhang = height % fourDip;
        if (overhang != 0) {
            super.setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
                    unalignedBottomPadding + (int) (fourDip - overhang));
        }
    }
}

From source file:android.support.v7.view.menu.MenuPopupHelper.java

private void showPopup(int xOffset, int yOffset, boolean useOffsets, boolean showTitle) {
    final MenuPopup popup = getPopup();
    popup.setShowTitle(showTitle);/*ww w . j  a va2s  .  c  o  m*/

    if (useOffsets) {
        // If the resolved drop-down gravity is RIGHT, the popup's right
        // edge will be aligned with the anchor view. Adjust by the anchor
        // width such that the top-right corner is at the X offset.
        final int hgrav = GravityCompat.getAbsoluteGravity(mDropDownGravity,
                ViewCompat.getLayoutDirection(mAnchorView)) & Gravity.HORIZONTAL_GRAVITY_MASK;
        if (hgrav == Gravity.RIGHT) {
            xOffset -= mAnchorView.getWidth();
        }

        popup.setHorizontalOffset(xOffset);
        popup.setVerticalOffset(yOffset);

        // Set the transition epicenter to be roughly finger (or mouse
        // cursor) sized and centered around the offset position. This
        // will give the appearance that the window is emerging from
        // the touch point.
        final float density = mContext.getResources().getDisplayMetrics().density;
        final int halfSize = (int) (TOUCH_EPICENTER_SIZE_DP * density / 2);
        final Rect epicenter = new Rect(xOffset - halfSize, yOffset - halfSize, xOffset + halfSize,
                yOffset + halfSize);
        popup.setEpicenterBounds(epicenter);
    }

    popup.show();
}

From source file:xyz.berial.textinputlayout.CollapsingTextHelper.java

private void calculateBaseOffsets() {
    // We then calculate the collapsed text size, using the same logic
    mTextPaint.setTextSize(mCollapsedTextSize);
    float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mCollapsedDrawY = mCollapsedBounds.bottom;
        break;/* w ww .  j a v  a  2s .co  m*/
    case Gravity.TOP:
        mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset;
        break;
    }
    switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mCollapsedDrawX = mCollapsedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mCollapsedDrawX = mCollapsedBounds.left;
        break;
    }

    mTextPaint.setTextSize(mExpandedTextSize);
    width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mExpandedDrawY = mExpandedBounds.bottom;
        break;
    case Gravity.TOP:
        mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mExpandedDrawY = mExpandedBounds.centerY() + textOffset;
        break;
    }
    switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mExpandedDrawX = mExpandedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mExpandedDrawX = mExpandedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mExpandedDrawX = mExpandedBounds.left;
        break;
    }

    // The bounds have changed so we need to clear the texture
    clearTexture();
}

From source file:com.nile.kmooc.view.custom.popup.menu.MenuPopupHelper.java

public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mPopup.setAdapter(mAdapter);/*from w ww  . ja  va 2 s . c om*/
    mPopup.setModal(true);

    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest
        if (addGlobalListener)
            mTreeObserver.addOnGlobalLayoutListener(this);
        anchor.addOnAttachStateChangeListener(this);
        mPopup.setAnchorView(anchor);
        mPopup.setDropDownGravity(mDropDownGravity);
    } else {
        return false;
    }

    if (mContentWidth == Integer.MIN_VALUE) {
        mContentWidth = measureContentWidth();
    }
    mPopup.setContentWidth(mContentWidth);
    // Invert the horizontal offset in RTL mode.
    if (ViewCompat.getLayoutDirection(mAnchorView) == ViewCompat.LAYOUT_DIRECTION_RTL) {
        mPopup.setHorizontalOffset(-mPopup.getHorizontalOffset());
    }
    // Implement right gravity manually through horizontal offset pre-KitKat.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
            && (Gravity.getAbsoluteGravity(mDropDownGravity, ViewCompat.getLayoutDirection(anchor))
                    & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.RIGHT) {
        mPopup.setHorizontalOffset(mPopup.getHorizontalOffset() + (mAnchorView.getWidth() - mPopup.getWidth()));
    }
    // If vertical offset is defined as 0, then ListPopupWindow infers
    // it as the negative of the top padding of the background, in
    // order to anchor the content area. Since that is not the effect
    // we want, we'll force it to use only the explicitly defined
    // offset by explicitly setting it dynamically as well, and thus
    // forcing it to discard it's 'unset' flag.
    mPopup.setVerticalOffset(mPopup.getVerticalOffset());
    // Top/bottom padding will be applied on the background drawable,
    // as the ListView is both initialized and set up only after show()
    // is called on the ListPopupWindow. Left/right padding will be
    // set up on the list items from the adapter, to keep the correct
    // item boundaries for the selector.
    ShapeDrawable paddedDrawable = new ShapeDrawable();
    paddedDrawable.setAlpha(0);
    // Don't apply top padding if the first item is a header, to
    // comply with the design.
    paddedDrawable.setPadding(0, mAdapter.hasHeader() ? 0 : (mPopupPaddingTop - mPopupItemVerticalPadding), 0,
            mPopupPaddingBottom - mPopupItemVerticalPadding);
    Drawable background = mPopup.getBackground();
    mPopup.setBackgroundDrawable(background == null ? paddedDrawable
            : new LayerDrawable(new Drawable[] { background, paddedDrawable }));
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}

From source file:com.acbelter.directionalcarousel.CarouselViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int width = MeasureSpec.getSize(widthMeasureSpec);
    final int height = MeasureSpec.getSize(heightMeasureSpec);

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    if (DEBUG) {/*  w ww.  j  a  v a2  s .  co m*/
        Log.d(TAG, "w=" + width + " h=" + height);
        Log.d(TAG, "wMode=" + getModeDescription(widthMode) + " hMode=" + getModeDescription(heightMode));
    }

    // FIXME Supported only match_parent and wrap_content attributes
    if (mConfig.orientation == CarouselConfig.VERTICAL) {
        int pageContentWidth = getPageContentWidth();
        int newWidth = width;
        if (widthMode == MeasureSpec.AT_MOST || pageContentWidth + 2 * mWrapPadding > width) {

            newWidth = pageContentWidth + 2 * mWrapPadding;
            widthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth, widthMode);
        }

        ViewGroup.LayoutParams lp = getLayoutParams();
        // FIXME Supported only FrameLayout as parent
        if (lp instanceof FrameLayout.LayoutParams) {
            if (!parentHasExactDimensions()) {
                throw new UnsupportedOperationException("Parent layout should have exact " + "dimensions.");
            }

            FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lp;
            if (!mSizeChanged) {
                gravityOffset = 0.0f;
                int hGrav = params.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                if (hGrav == Gravity.CENTER_HORIZONTAL || hGrav == Gravity.CENTER) {
                    gravityOffset = (width - newWidth) * 0.5f;
                }
                if (hGrav == Gravity.RIGHT) {
                    gravityOffset = width - newWidth;
                }
            }

            setRotation(90);
            setTranslationX((newWidth - height) * 0.5f + gravityOffset);
            setTranslationY(-(newWidth - height) * 0.5f);
            params.gravity = Gravity.NO_GRAVITY;
            setLayoutParams(params);
        } else {
            throw new UnsupportedOperationException("Parent layout should be instance of " + "FrameLayout.");
        }

        mSizeChanged = true;
        super.onMeasure(heightMeasureSpec, widthMeasureSpec);
    } else {
        int pageContentHeight = getPageContentHeight();
        if (heightMode == MeasureSpec.AT_MOST || pageContentHeight + 2 * mWrapPadding > height) {

            int newHeight = pageContentHeight + 2 * mWrapPadding;
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight, heightMode);
        }

        // FIXME Supported only FrameLayout as parent
        if (!(getLayoutParams() instanceof FrameLayout.LayoutParams)) {
            throw new UnsupportedOperationException("Parent layout should be instance of " + "FrameLayout.");
        } else {
            if (!parentHasExactDimensions()) {
                throw new UnsupportedOperationException("Parent layout should have exact " + "dimensions.");
            }
        }

        mSizeChanged = true;
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    mViewPagerWidth = getMeasuredWidth();
    mViewPagerHeight = getMeasuredHeight();

    if (calculatePageLimitAndMargin()) {
        setOffscreenPageLimit(mConfig.pageLimit);
        setPageMargin(mConfig.pageMargin);
    }

    if (DEBUG) {
        Log.d(TAG, mConfig.toString());
    }
}