Example usage for android.view View offsetLeftAndRight

List of usage examples for android.view View offsetLeftAndRight

Introduction

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

Prototype

public void offsetLeftAndRight(int offset) 

Source Link

Document

Offset this view's horizontal location by the specified amount of pixels.

Usage

From source file:com.hippo.nimingban.widget.PostLayout.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    for (int i = 0, count = getChildCount(); i < count; i++) {
        View child = getChildAt(i);
        if (GONE == child.getVisibility()) {
            continue;
        }/*from   w  ww . j  a va2  s . com*/

        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        child.offsetLeftAndRight(lp.offsetX);
        child.offsetTopAndBottom(lp.offsetY);
    }
}

From source file:android.support.v17.leanback.widget.DetailsOverviewSharedElementHelper.java

@Override
public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements,
        List<View> sharedElementSnapshots) {
    if (DEBUG) {// w  ww. ja v  a2  s. c o  m
        Log.d(TAG, "onSharedElementStart " + mActivityToRunTransition);
    }
    if (sharedElements.size() < 1) {
        return;
    }
    View overviewView = sharedElements.get(0);
    if (mViewHolder == null || mViewHolder.mOverviewFrame != overviewView) {
        return;
    }
    View snapshot = sharedElementSnapshots.get(0);
    if (hasImageViewScaleChange(snapshot)) {
        saveImageViewScale();
        changeImageViewScale(snapshot);
    }
    View imageView = mViewHolder.mImageView;
    final int width = overviewView.getWidth();
    final int height = overviewView.getHeight();
    imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
    imageView.layout(0, 0, width, height);
    final View rightPanel = mViewHolder.mRightPanel;
    if (mRightPanelWidth != 0 && mRightPanelHeight != 0) {
        rightPanel.measure(MeasureSpec.makeMeasureSpec(mRightPanelWidth, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(mRightPanelHeight, MeasureSpec.EXACTLY));
        rightPanel.layout(width, rightPanel.getTop(), width + mRightPanelWidth,
                rightPanel.getTop() + mRightPanelHeight);
    } else {
        rightPanel.offsetLeftAndRight(width - rightPanel.getLeft());
    }
    mViewHolder.mActionsRow.setVisibility(View.INVISIBLE);
    mViewHolder.mDetailsDescriptionFrame.setVisibility(View.INVISIBLE);
}

From source file:com.cocosw.accessory.views.adapter.AdapterViewAnimator.java

public void animate() {
    if (animateCalled) {
        throw new RuntimeException("animate must only be called once");
    }/*ww w  .  ja v  a  2  s .c om*/
    animateCalled = true;

    final ViewTreeObserver observer = adapterView.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            observer.removeOnPreDrawListener(this);

            Adapter adapter = adapterView.getAdapter();
            final int firstVisiblePosition = adapterView.getFirstVisiblePosition();
            for (int i = 0, childCount = adapterView.getChildCount(); i < childCount; i++) {
                final int position = firstVisiblePosition + i;
                final long id = adapter.getItemId(position);
                idToViewMap.remove(id);
                final View child = adapterView.getChildAt(i);

                final Rect bounds = viewBounds.get(id);
                Runnable endAction = new Runnable() {
                    @Override
                    public void run() {
                        ViewCompat.setHasTransientState(child, false);
                    }
                };
                if (bounds != null) {
                    if (callback == null
                            || !callback.onMoveView(adapterView, child, position, id, bounds, endAction)) {
                        final int dx = bounds.left - child.getLeft();
                        final int dy = bounds.top - child.getTop();
                        ViewCompat.setTranslationX(child, dx);
                        ViewCompat.setTranslationY(child, dy);
                        ViewCompat.animate(child).setDuration(DURATION_MOVE).translationX(0.0f)
                                .translationY(0.0f).withEndAction(endAction);
                    }
                } else {
                    if (callback == null || !callback.onAddView(adapterView, child, position, id)) {
                        ViewCompat.setAlpha(child, 0.0f);
                        ViewCompat.animate(child).setDuration(DURATION_ADD).alpha(1.0f);
                    }
                }
            }

            int[] adapterViewLocation = new int[2];
            int[] hostViewLocation = new int[2];
            final int size = idToViewMap.size();
            for (int i = 0; i < size; i++) {
                final long id = idToViewMap.keyAt(i);
                final View child = idToViewMap.get(id);
                ViewCompat.setHasTransientState(child, false);
                final View viewCopy = new ViewCopy(child);
                Rect bounds = viewBounds.get(id);

                if (overlay == null) {
                    ViewGroup parent = (ViewGroup) adapterView.getParent();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
                        overlay = parent.getOverlay();
                    adapterView.getLocationOnScreen(adapterViewLocation);
                    parent.getLocationOnScreen(hostViewLocation);
                }

                overlay.add(viewCopy);
                viewCopy.offsetLeftAndRight(adapterViewLocation[0] - hostViewLocation[0]);
                viewCopy.offsetTopAndBottom(adapterViewLocation[1] - hostViewLocation[1]);

                if (callback == null || !callback.onRemoveView(adapterView, viewCopy, id, bounds)) {
                    ViewCompat.animate(viewCopy).setDuration(DURATION_REMOVE).alpha(0.0f)
                            .withEndAction(new Runnable() {
                                @Override
                                public void run() {
                                    overlay.remove(viewCopy);
                                }
                            });
                }
            }

            return true;
        }
    });
}

From source file:am.widget.multifunctionalrecyclerview.layoutmanager.BothDirectionsScrollLayoutManager.java

@Override
public void layoutDecorated(@NonNull View child, int left, int top, int right, int bottom) {
    super.layoutDecorated(child, left, top, right, bottom);
    final int offset = computeAnotherDirectionDefaultScrollOffset();
    final int move = offset - mOffset;
    if (move == 0)
        return;// w  ww.  ja  v a  2  s.  c o  m
    if (getOrientation() == HORIZONTAL) {
        child.offsetTopAndBottom(move);
    } else {
        child.offsetLeftAndRight(move);
    }
}

From source file:am.widget.multifunctionalrecyclerview.layoutmanager.BothDirectionsScrollLayoutManager.java

@Override
public void layoutDecoratedWithMargins(@NonNull View child, int left, int top, int right, int bottom) {
    super.layoutDecoratedWithMargins(child, left, top, right, bottom);
    final int offset = computeAnotherDirectionDefaultScrollOffset();
    final int move = offset - mOffset;
    if (move == 0)
        return;/* w w  w. j av a  2 s . com*/
    if (getOrientation() == HORIZONTAL) {
        child.offsetTopAndBottom(move);
    } else {
        child.offsetLeftAndRight(move);
    }
}

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

/**
 * Creates and positions all views for this Spinner.
 *
 * @param delta Change in the selected position. +1 moves selection is moving to the right,
 * so views are scrolling to the left. -1 means selection is moving to the left.
 *///from  w  ww  .j a va2 s . co  m
@Override
void layout(int delta, boolean animate) {
    int childrenLeft = mSpinnerPadding.left;
    int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right;

    if (mDataChanged) {
        handleDataChanged();
    }

    // Handle the empty set by removing all views
    if (mItemCount == 0) {
        resetList();
        return;
    }

    if (mNextSelectedPosition >= 0) {
        setSelectedPositionInt(mNextSelectedPosition);
    }

    recycleAllViews();

    // Clear out old views
    removeAllViewsInLayout();

    // Make selected view and position it
    mFirstPosition = mSelectedPosition;
    View sel = makeAndAddView(mSelectedPosition);
    int width = sel.getMeasuredWidth();
    int selectedOffset = childrenLeft;
    switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2);
        break;
    case Gravity.RIGHT:
        selectedOffset = childrenLeft + childrenWidth - width;
        break;
    }
    sel.offsetLeftAndRight(selectedOffset);

    // Flush any cached views that did not get reused above
    mRecycler.clear();

    invalidate();

    checkSelectionChanged();

    mDataChanged = false;
    mNeedSync = false;
    setNextSelectedPositionInt(mSelectedPosition);
}

From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {

    if (changed || mDataChanged) {
        handleDataChanged();/*w w  w .  j a  v a 2s  .  com*/
    }

    if (mItemCount < 1) {
        return;
    }

    final int width = right - left;

    if (mDataChanged) {
        if (mCurrentScreen > INVALID_SCREEN)
            scrollTo(mCurrentScreen * width, 0);
        else
            scrollTo(0, 0);
    }

    if (mNextScreen > INVALID_SCREEN) {
        setSelectedPositionInt(mNextScreen);
    }

    if (mDataChanged) {
        mFirstPosition = mDefaultScreen;
        int childrenLeft = mPaddingLeft;
        int childrenWidth = (getRight() - getLeft()) - (mPaddingLeft + mPaddingRight);
        View sel = makeAndAddView(mCurrentScreen, 0, 0, true);
        int selectedOffset = childrenLeft + (childrenWidth / 2) - (sel.getWidth() / 2);
        sel.offsetLeftAndRight(selectedOffset);
        fillToGalleryRight();
        fillToGalleryLeft();
        checkSelectionChanged();
    }

    mDataChanged = false;
    setNextSelectedPositionInt(mCurrentScreen);

    if (changed && !mDataChanged) {
        layoutChildren();
    }
}

From source file:com.quran.labs.androidquran.widgets.spinner.SpinnerCompat.java

/**
 * Creates and positions all views for this Spinner.
 *
 * @param delta Change in the selected position. +1 means selection is moving to the right, so
 *              views are scrolling to the left. -1 means selection is moving to the left.
 *///  w w w .  ja va  2s.  c  o  m
@SuppressLint("RtlHardcoded")
@Override
void layout(int delta, boolean animate) {
    int childrenLeft = mSpinnerPadding.left;
    int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right;

    if (mDataChanged) {
        handleDataChanged();
    }

    // Handle the empty set by removing all views
    if (mItemCount == 0) {
        resetList();
        return;
    }

    if (mNextSelectedPosition >= 0) {
        setSelectedPositionInt(mNextSelectedPosition);
    }

    recycleAllViews();

    // Clear out old views
    removeAllViewsInLayout();

    // Make selected view and position it
    mFirstPosition = mSelectedPosition;
    if (mAdapter != null) {
        View sel = makeView(mSelectedPosition, true);
        int width = sel.getMeasuredWidth();
        int selectedOffset = childrenLeft;
        final int layoutDirection = ViewCompat.getLayoutDirection(this);
        final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection);
        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2);
            break;
        case Gravity.RIGHT:
            selectedOffset = childrenLeft + childrenWidth - width;
            break;
        }
        sel.offsetLeftAndRight(selectedOffset);
    }

    // Flush any cached views that did not get reused above
    mRecycler.clear();

    invalidate();

    checkSelectionChanged();

    mDataChanged = false;
    mNeedSync = false;
    setNextSelectedPositionInt(mSelectedPosition);
}

From source file:android.support.v7.internal.widget.SpinnerCompat.java

/**
 * Creates and positions all views for this Spinner.
 *
 * @param delta Change in the selected position. +1 means selection is moving to the right, so
 *              views are scrolling to the left. -1 means selection is moving to the left.
 */// ww w . j a  v  a2s  .c  om
@Override
void layout(int delta, boolean animate) {
    int childrenLeft = mSpinnerPadding.left;
    int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right;

    if (mDataChanged) {
        handleDataChanged();
    }

    // Handle the empty set by removing all views
    if (mItemCount == 0) {
        resetList();
        return;
    }

    if (mNextSelectedPosition >= 0) {
        setSelectedPositionInt(mNextSelectedPosition);
    }

    recycleAllViews();

    // Clear out old views
    removeAllViewsInLayout();

    // Make selected view and position it
    mFirstPosition = mSelectedPosition;
    if (mAdapter != null) {
        View sel = makeView(mSelectedPosition, true);
        int width = sel.getMeasuredWidth();
        int selectedOffset = childrenLeft;
        final int layoutDirection = ViewCompat.getLayoutDirection(this);
        final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection);
        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2);
            break;
        case Gravity.RIGHT:
            selectedOffset = childrenLeft + childrenWidth - width;
            break;
        }
        sel.offsetLeftAndRight(selectedOffset);
    }

    // Flush any cached views that did not get reused above
    mRecycler.clear();

    invalidate();

    checkSelectionChanged();

    mDataChanged = false;
    mNeedSync = false;
    setNextSelectedPositionInt(mSelectedPosition);
}

From source file:android.widget.Gallery.java

/**
 * Creates and positions all views for this Gallery.
 * <p>//from w  w  w. j  a va 2s. c  om
 * We layout rarely, most of the time {@link #trackMotionScroll(int)} takes
 * care of repositioning, adding, and removing children.
 * 
 * @param delta Change in the selected position. +1 means the selection is
 *            moving to the right, so views are scrolling to the left. -1
 *            means the selection is moving to the left.
 */
@Override
void layout(int delta, boolean animate) {

    mIsRtl = isLayoutRtl();

    int childrenLeft = mSpinnerPadding.left;
    int childrenWidth = mRight - mLeft - mSpinnerPadding.left - mSpinnerPadding.right;

    if (mDataChanged) {
        handleDataChanged();
    }

    // Handle an empty gallery by removing all views.
    if (mItemCount == 0) {
        resetList();
        return;
    }

    // Update to the new selected position.
    if (mNextSelectedPosition >= 0) {
        setSelectedPositionInt(mNextSelectedPosition);
    }

    // All views go in recycler while we are in layout
    recycleAllViews();

    // Clear out old views
    //removeAllViewsInLayout();
    detachAllViewsFromParent();

    /*
     * These will be used to give initial positions to views entering the
     * gallery as we scroll
     */
    mRightMost = 0;
    mLeftMost = 0;

    // Make selected view and center it

    /*
     * mFirstPosition will be decreased as we add views to the left later
     * on. The 0 for x will be offset in a couple lines down.
     */
    mFirstPosition = mSelectedPosition;
    View sel = makeAndAddView(mSelectedPosition, 0, 0, true);

    // Put the selected child in the center
    int selectedOffset = childrenLeft + (childrenWidth / 2) - (sel.getWidth() / 2) + mSelectedCenterOffset;
    sel.offsetLeftAndRight(selectedOffset);

    fillToGalleryRight();
    fillToGalleryLeft();

    // Flush any cached views that did not get reused above
    mRecycler.clear();

    invalidate();
    checkSelectionChanged();

    mDataChanged = false;
    mNeedSync = false;
    setNextSelectedPositionInt(mSelectedPosition);

    updateSelectedItemMetadata();
}