Example usage for android.view View getLeft

List of usage examples for android.view View getLeft

Introduction

In this page you can find the example usage for android.view View getLeft.

Prototype

@ViewDebug.CapturedViewProperty
public final int getLeft() 

Source Link

Document

Left position of this view relative to its parent.

Usage

From source file:com.benny.openlauncher.widget.SmoothViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns./*from  w ww .j  a  va  2 s .  co  m*/
 *
 * @param position     Position index of the first page currently being displayed.
 *                     Page position+1 will be visible if positionOffset is nonzero.
 * @param offset       Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
@CallSuper
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollX = getScrollX();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        final int width = getWidth();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childLeft = 0;
            switch (hgrav) {
            default:
                childLeft = paddingLeft;
                break;
            case Gravity.LEFT:
                childLeft = paddingLeft;
                paddingLeft += child.getWidth();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                break;
            case Gravity.RIGHT:
                childLeft = width - paddingRight - child.getMeasuredWidth();
                paddingRight += child.getMeasuredWidth();
                break;
            }
            childLeft += scrollX;

            final int childOffset = childLeft - child.getLeft();
            if (childOffset != 0) {
                child.offsetLeftAndRight(childOffset);
            }
        }
    }

    dispatchOnPageScrolled(position, offset, offsetPixels);

    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

From source file:cn.trinea.android.common.view.CycleViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns.//from   w  w w  .jav a2  s.c  om
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollX = getScrollX();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        final int width = getWidth();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childLeft = 0;
            switch (hgrav) {
            default:
                childLeft = paddingLeft;
                break;
            case Gravity.LEFT:
                childLeft = paddingLeft;
                paddingLeft += child.getWidth();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                break;
            case Gravity.RIGHT:
                childLeft = width - paddingRight - child.getMeasuredWidth();
                paddingRight += child.getMeasuredWidth();
                break;
            }
            childLeft += scrollX;

            final int childOffset = childLeft - child.getLeft();
            if (childOffset != 0) {
                child.offsetLeftAndRight(childOffset);
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            final float transformPos = (float) (child.getLeft() - scrollX) / getWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

From source file:com.android.launcher2.Workspace.java

void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) {
    if (cachedInverseMatrix == null) {
        v.getMatrix().invert(mTempInverseMatrix);
        cachedInverseMatrix = mTempInverseMatrix;
    }/*  w ww.j a v  a2s.  c  o m*/
    int scrollX = getScrollX();
    if (mNextPage != INVALID_PAGE) {
        scrollX = mScroller.getFinalX();
    }
    xy[0] = xy[0] + scrollX - v.getLeft();
    xy[1] = xy[1] + getScrollY() - v.getTop();
    cachedInverseMatrix.mapPoints(xy);
}

From source file:com.appunite.list.HorizontalListView.java

/**
 * Determine how much we need to scroll in order to get the next selected view
 * visible, with a fading edge showing below as applicable.  The amount is
 * capped at {@link #getMaxScrollAmount()} .
 *
 * @param direction either {@link android.view.View#FOCUS_UP} or
 *        {@link android.view.View#FOCUS_DOWN}.
 * @param nextSelectedPosition The position of the next selection, or
 *        {@link #INVALID_POSITION} if there is no next selectable position
 * @return The amount to scroll. Note: this is always positive!  Direction
 *         needs to be taken into account when actually scrolling.
 *//*from  ww w . j  a  v a 2s.  co m*/
private int amountToScroll(int direction, int nextSelectedPosition) {
    final int listRight = getWidth() - mListPadding.right;
    final int listLeft = mListPadding.left;

    int numChildren = getChildCount();

    if (direction == View.FOCUS_DOWN) {
        int indexToMakeVisible = numChildren - 1;
        if (nextSelectedPosition != INVALID_POSITION) {
            indexToMakeVisible = nextSelectedPosition - mFirstPosition;
        }
        while (numChildren <= indexToMakeVisible) {
            // Child to view is not attached yet.
            addViewToRight(getChildAt(numChildren - 1), mFirstPosition + numChildren - 1);
            numChildren++;
        }
        final int positionToMakeVisible = mFirstPosition + indexToMakeVisible;
        final View viewToMakeVisible = getChildAt(indexToMakeVisible);

        int goalRight = listRight;
        if (positionToMakeVisible < mItemCount - 1) {
            goalRight -= getArrowScrollPreviewLength();
        }

        if (viewToMakeVisible.getRight() <= goalRight) {
            // item is fully visible.
            return 0;
        }

        if (nextSelectedPosition != INVALID_POSITION
                && (goalRight - viewToMakeVisible.getLeft()) >= getMaxScrollAmount()) {
            // item already has enough of it visible, changing selection is good enough
            return 0;
        }

        int amountToScroll = (viewToMakeVisible.getRight() - goalRight);

        if ((mFirstPosition + numChildren) == mItemCount) {
            // last is last in list -> make sure we don't scroll past it
            final int max = getChildAt(numChildren - 1).getRight() - listRight;
            amountToScroll = Math.min(amountToScroll, max);
        }

        return Math.min(amountToScroll, getMaxScrollAmount());
    } else {
        int indexToMakeVisible = 0;
        if (nextSelectedPosition != INVALID_POSITION) {
            indexToMakeVisible = nextSelectedPosition - mFirstPosition;
        }
        while (indexToMakeVisible < 0) {
            // Child to view is not attached yet.
            addViewToLeft(getChildAt(0), mFirstPosition);
            mFirstPosition--;
            indexToMakeVisible = nextSelectedPosition - mFirstPosition;
        }
        final int positionToMakeVisible = mFirstPosition + indexToMakeVisible;
        final View viewToMakeVisible = getChildAt(indexToMakeVisible);
        int goalLeft = listLeft;
        if (positionToMakeVisible > 0) {
            goalLeft += getArrowScrollPreviewLength();
        }
        if (viewToMakeVisible.getLeft() >= goalLeft) {
            // item is fully visible.
            return 0;
        }

        if (nextSelectedPosition != INVALID_POSITION
                && (viewToMakeVisible.getRight() - goalLeft) >= getMaxScrollAmount()) {
            // item already has enough of it visible, changing selection is good enough
            return 0;
        }

        int amountToScroll = (goalLeft - viewToMakeVisible.getLeft());
        if (mFirstPosition == 0) {
            // first is first in list -> make sure we don't scroll past it
            final int max = listLeft - getChildAt(0).getLeft();
            amountToScroll = Math.min(amountToScroll, max);
        }
        return Math.min(amountToScroll, getMaxScrollAmount());
    }
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * Determine how much we need to scroll in order to get the next selected view visible, with a fading edge showing below as
 * applicable. The amount is capped at {@link #getMaxScrollAmount()} .
 * //from  w  ww  .  ja va  2s  .c o m
 * @param direction
 *           either {@link android.view.View#FOCUS_UP} or {@link android.view.View#FOCUS_DOWN}.
 * @param nextSelectedPosition
 *           The position of the next selection, or {@link #INVALID_POSITION} if there is no next selectable position
 * @return The amount to scroll. Note: this is always positive! Direction needs to be taken into account when actually scrolling.
 */
private int amountToScroll(int direction, int nextSelectedPosition) {
    final int listRight = getWidth() - mListPadding.right;
    final int listLeft = mListPadding.left;

    final int numChildren = getChildCount();

    if (direction == View.FOCUS_DOWN) {
        int indexToMakeVisible = numChildren - 1;
        if (nextSelectedPosition != INVALID_POSITION) {
            indexToMakeVisible = nextSelectedPosition - mFirstPosition;
        }

        final int positionToMakeVisible = mFirstPosition + indexToMakeVisible;
        final View viewToMakeVisible = getChildAt(indexToMakeVisible);

        int goalRight = listRight;
        if (positionToMakeVisible < mItemCount - 1) {
            goalRight -= getArrowScrollPreviewLength();
        }

        if (viewToMakeVisible.getRight() <= goalRight) {
            // item is fully visible.
            return 0;
        }

        if (nextSelectedPosition != INVALID_POSITION
                && (goalRight - viewToMakeVisible.getLeft()) >= getMaxScrollAmount()) {
            // item already has enough of it visible, changing selection is good enough
            return 0;
        }

        int amountToScroll = (viewToMakeVisible.getRight() - goalRight);

        if ((mFirstPosition + numChildren) == mItemCount) {
            // last is last in list -> make sure we don't scroll past it
            final int max = getChildAt(numChildren - 1).getRight() - listRight;
            amountToScroll = Math.min(amountToScroll, max);
        }

        return Math.min(amountToScroll, getMaxScrollAmount());
    } else {
        int indexToMakeVisible = 0;
        if (nextSelectedPosition != INVALID_POSITION) {
            indexToMakeVisible = nextSelectedPosition - mFirstPosition;
        }
        final int positionToMakeVisible = mFirstPosition + indexToMakeVisible;
        final View viewToMakeVisible = getChildAt(indexToMakeVisible);
        int goalLeft = listLeft;
        if (positionToMakeVisible > 0) {
            goalLeft += getArrowScrollPreviewLength();
        }
        if (viewToMakeVisible.getLeft() >= goalLeft) {
            // item is fully visible.
            return 0;
        }

        if (nextSelectedPosition != INVALID_POSITION
                && (viewToMakeVisible.getRight() - goalLeft) >= getMaxScrollAmount()) {
            // item already has enough of it visible, changing selection is good enough
            return 0;
        }

        int amountToScroll = (goalLeft - viewToMakeVisible.getLeft());
        if (mFirstPosition == 0) {
            // first is first in list -> make sure we don't scroll past it
            final int max = listLeft - getChildAt(0).getLeft();
            amountToScroll = Math.min(amountToScroll, max);
        }
        return Math.min(amountToScroll, getMaxScrollAmount());
    }
}

From source file:com.baiiu.autoloopviewpager.loopvp.LoopViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as
 * part of a programmatically initiated smooth scroll or a user initiated
 * touch scroll. If you override this method you must call through to the
 * superclass implementation (e.g. super.onPageScrolled(position, offset,
 * offsetPixels)) before onPageScrolled returns.
 *
 * @param position Position index of the first page currently being displayed.
 * Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at
 * position.//from  w  w w .j a v  a 2s  . c o  m
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollX = getScrollX();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        final int width = getWidth();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childLeft = 0;
            switch (hgrav) {
            default:
                childLeft = paddingLeft;
                break;
            case Gravity.LEFT:
                childLeft = paddingLeft;
                paddingLeft += child.getWidth();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                break;
            case Gravity.RIGHT:
                childLeft = width - paddingRight - child.getMeasuredWidth();
                paddingRight += child.getMeasuredWidth();
                break;
            }
            childLeft += scrollX;

            final int childOffset = childLeft - child.getLeft();
            if (childOffset != 0) {
                child.offsetLeftAndRight(childOffset);
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    if (mOnPageChangeListeners != null) {
        for (int i = 0, z = mOnPageChangeListeners.size(); i < z; i++) {
            OnPageChangeListener listener = mOnPageChangeListeners.get(i);
            if (listener != null) {
                listener.onPageScrolled(position, offset, offsetPixels);
            }
        }
    }

    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    mCalledSuper = true;
}

From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns.//from ww  w .  j  a  va2  s .co m
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollX = getScrollX();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        final int width = getWidth();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childLeft = 0;
            switch (hgrav) {
            default:
                childLeft = paddingLeft;
                break;
            case Gravity.LEFT:
                childLeft = paddingLeft;
                paddingLeft += child.getWidth();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                break;
            case Gravity.RIGHT:
                childLeft = width - paddingRight - child.getMeasuredWidth();
                paddingRight += child.getMeasuredWidth();
                break;
            }
            childLeft += scrollX;

            final int childOffset = childLeft - child.getLeft();
            if (childOffset != 0) {
                child.offsetLeftAndRight(childOffset);
            }
        }
    }

    if (mOnPageChangeListener != null) {
        mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }
    if (mInternalPageChangeListener != null) {
        mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
    }

    transformPages();

    mCalledSuper = true;
}

From source file:com.android.launcher3.ViewPager.java

/**
 * This method will be invoked when the current page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns./*from  w  w  w  .ja va 2  s  .  c o  m*/
 *
 * @param position     Position index of the first page currently being displayed.
 *                     Page position+1 will be visible if positionOffset is nonzero.
 * @param offset       Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
@CallSuper
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    mPosition = position;
    off = offset;
    if (mDecorChildCount > 0) {
        final int scrollX = getScrollX();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        final int width = getWidth();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childLeft = 0;
            switch (hgrav) {
            default:
                childLeft = paddingLeft;
                break;
            case Gravity.LEFT:
                childLeft = paddingLeft;
                paddingLeft += child.getWidth();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                break;
            case Gravity.RIGHT:
                childLeft = width - paddingRight - child.getMeasuredWidth();
                paddingRight += child.getMeasuredWidth();
                break;
            }
            childLeft += scrollX;

            final int childOffset = childLeft - child.getLeft();
            if (childOffset != 0) {
                child.offsetLeftAndRight(childOffset);
            }
        }
    }

    dispatchOnPageScrolled(position, offset, offsetPixels);

    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * NOTE This method is borrowed from {@link ScrollView}.
 *///  ww w  .jav a  2s  .  c o m
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
    // offset into coordinate space of this scroll view
    rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());

    return scrollToChildRect(rectangle, immediate);
}

From source file:com.av.remusic.widget.RoundViewPager.java

/**
 * This method will be invoked when the currentPosition page is scrolled, either as part
 * of a programmatically initiated smooth scroll or a user initiated touch scroll.
 * If you override this method you must call through to the superclass implementation
 * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
 * returns./*from  www. j  av  a 2 s .c o  m*/
 *
 * @param position Position index of the first page currently being displayed.
 *                 Page position+1 will be visible if positionOffset is nonzero.
 * @param offset Value from [0, 1) indicating the offset from the page at position.
 * @param offsetPixels Value in pixels indicating the offset from position.
 */
@CallSuper
protected void onPageScrolled(int position, float offset, int offsetPixels) {
    // Offset any decor views if needed - keep them on-screen at all times.
    if (mDecorChildCount > 0) {
        final int scrollX = getScrollX();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        final int width = getWidth();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.isDecor)
                continue;

            final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
            int childLeft = 0;
            switch (hgrav) {
            default:
                childLeft = paddingLeft;
                break;
            case Gravity.LEFT:
                childLeft = paddingLeft;
                paddingLeft += child.getWidth();
                break;
            case Gravity.CENTER_HORIZONTAL:
                childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                break;
            case Gravity.RIGHT:
                childLeft = width - paddingRight - child.getMeasuredWidth();
                paddingRight += child.getMeasuredWidth();
                break;
            }
            childLeft += scrollX;

            final int childOffset = childLeft - child.getLeft();
            if (childOffset != 0) {
                child.offsetLeftAndRight(childOffset);
            }
        }
    }

    dispatchOnPageScrolled(position, offset, offsetPixels);

    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;
            final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth();
            mPageTransformer.transformPage(child, transformPos);
        }
    }

    mCalledSuper = true;
}