Java Code Examples for android.view.View#offsetLeftAndRight()

The following examples show how to use android.view.View#offsetLeftAndRight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResideLayout.java    From ResideLayout with Apache License 2.0 6 votes vote down vote up
private void parallaxOtherViews(float slideOffset) {
    final LayoutParams slideLp = (LayoutParams) mSlideableView.getLayoutParams();
    final boolean dimViews = slideLp.dimWhenOffset && slideLp.leftMargin <= 0;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View v = getChildAt(i);
        if (v == mSlideableView) continue;

        final int oldOffset = (int) ((1 - mParallaxOffset) * mParallaxBy);
        mParallaxOffset = slideOffset;
        final int newOffset = (int) ((1 - slideOffset) * mParallaxBy);
        final int dx = oldOffset - newOffset;

        v.offsetLeftAndRight(dx);

        if (dimViews) {
            dimChildView(v, 1 - mParallaxOffset, mCoveredFadeColor);
        }
    }
}
 
Example 2
Source File: HListView.java    From letv with Apache License 2.0 6 votes vote down vote up
private View fillFromMiddle(int childrenLeft, int childrenRight) {
    int width = childrenRight - childrenLeft;
    int position = reconcileSelectedPosition();
    View sel = makeAndAddView(position, childrenLeft, true, this.mListPadding.top, true);
    this.mFirstPosition = position;
    int selWidth = sel.getMeasuredWidth();
    if (selWidth <= width) {
        sel.offsetLeftAndRight((width - selWidth) / 2);
    }
    fillBeforeAndAfter(sel, position);
    if (this.mStackFromRight) {
        correctTooSmall(getChildCount());
    } else {
        correctTooWide(getChildCount());
    }
    return sel;
}
 
Example 3
Source File: DrawerFrameV2.java    From support with Apache License 2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() == GONE) continue;
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (child.getId() == R.id.menu) {
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childLeft = 0;
            child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight);
            child.offsetLeftAndRight(-mLeftViewWidth);
        } else if (child.getId() == R.id.main) {
            child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
        }
    }
}
 
Example 4
Source File: SlidingPaneLayout.java    From KlyphMessenger with MIT License 6 votes vote down vote up
private void parallaxOtherViews(float slideOffset) {
    final LayoutParams slideLp = (LayoutParams) mSlideableView.getLayoutParams();
    final boolean dimViews = slideLp.dimWhenOffset && slideLp.leftMargin <= 0;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View v = getChildAt(i);
        if (v == mSlideableView) continue;

        final int oldOffset = (int) ((1 - mParallaxOffset) * mParallaxBy);
        mParallaxOffset = slideOffset;
        final int newOffset = (int) ((1 - slideOffset) * mParallaxBy);
        final int dx = oldOffset - newOffset;

        v.offsetLeftAndRight(dx);

        if (dimViews) {
            dimChildView(v, 1 - mParallaxOffset, mCoveredFadeColor);
        }
    }
}
 
Example 5
Source File: SwipeBackLayout.java    From AndroidProjects with MIT License 5 votes vote down vote up
private void parallaxOtherViews(float slideOffset) {
        final boolean isLayoutRtl = isLayoutRtlSupport();
        final LayoutParams slideLp = (LayoutParams) mSlideableView.getLayoutParams();
        final boolean dimViews = slideLp.dimWhenOffset
                && (isLayoutRtl ? slideLp.rightMargin : slideLp.leftMargin) <= 0;
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == mSlideableView) continue;

            final int oldOffset = (int) ((1 - mParallaxOffset) * mParallaxBy);
            mParallaxOffset = slideOffset;
            final int newOffset = (int) ((1 - slideOffset) * mParallaxBy);
            final int dx = oldOffset - newOffset;

//            v.offsetLeftAndRight(isLayoutRtl ? -dx : dx);
            if (isLayoutRtl) {
                v.offsetLeftAndRight(-dx);
            } else {
                v.offsetLeftAndRight(dx);
            }
            if (dimViews) {
                dimChildView(v, isLayoutRtl ? mParallaxOffset - 1
                        : 1 - mParallaxOffset, mCoveredFadeColor);
            }
        }
    }
 
Example 6
Source File: DrawerLayout.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
void moveDrawerToOffset(View drawerView, float slideOffset) {
    final float oldOffset = getDrawerViewOffset(drawerView);
    final int width = drawerView.getWidth();
    final int oldPos = (int) (width * oldOffset);
    final int newPos = (int) (width * slideOffset);
    final int dx = newPos - oldPos;

    drawerView.offsetLeftAndRight(checkDrawerViewGravity(drawerView, Gravity.LEFT) ? dx : -dx);
    setDrawerViewOffset(drawerView, slideOffset);
}
 
Example 7
Source File: PostLayout.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@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;
        }

        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        child.offsetLeftAndRight(lp.offsetX);
        child.offsetTopAndBottom(lp.offsetY);
    }
}
 
Example 8
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
void moveDrawerToOffset(View drawerView, float slideOffset) {
    final float oldOffset = getDrawerViewOffset(drawerView);
    final int width = drawerView.getWidth();
    final int oldPos = (int) (width * oldOffset);
    final int newPos = (int) (width * slideOffset);
    final int dx = newPos - oldPos;

    drawerView.offsetLeftAndRight(
            checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT) ? dx : -dx);
    setDrawerViewOffset(drawerView, slideOffset);
}
 
Example 9
Source File: ObservableWebViewWithHeader.java    From FadingActionBar with Apache License 2.0 5 votes vote down vote up
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);
    
    View title = getChildAt(0);
    if (title != null)   // undo horizontal scroll, so that title scrolls only vertically
       title.offsetLeftAndRight(l - title.getLeft());

    if (mOnScrollChangedCallback != null)
        mOnScrollChangedCallback.onScroll(l, t);
}
 
Example 10
Source File: BothDirectionsScrollLayoutManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@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;
    if (getOrientation() == HORIZONTAL) {
        child.offsetTopAndBottom(move);
    } else {
        child.offsetLeftAndRight(move);
    }
}
 
Example 11
Source File: MonthTitleView.java    From MonthView with Apache License 2.0 5 votes vote down vote up
protected void makeAndAddCellView(int left, int top, int index) {
	final boolean recycled = !scrapTitleViews.isEmpty();
	final View child = recycled ? (scrapTitleViews.remove(0)) : (adapter.createTitleView(this));
	adapter.bindTitleView(child, index);
	
	LayoutParams lp = child.getLayoutParams();
	if(lp == null){
		lp = new LayoutParams(titleWidth, titleHeight);
	}
	
	if(recycled){
		attachViewToParent(child, index, lp);
	}else{
		addViewInLayout(child, index, lp, true);
	}
	
	final boolean needToMeasure = !recycled || child.isLayoutRequested();
	
	if (needToMeasure) {
	    final int childWidthSpec = getChildMeasureSpec(
	            MeasureSpec.makeMeasureSpec(titleWidth, MeasureSpec.EXACTLY), 0, lp.width);
	    final int childHeightSpec = getChildMeasureSpec(
	            MeasureSpec.makeMeasureSpec(titleHeight, MeasureSpec.EXACTLY), 0, lp.height);
	    child.measure(childWidthSpec, childHeightSpec);
	} else {
	    cleanupLayoutState(child);
	}
	
	if (needToMeasure) {
		child.layout(left, top,left + titleWidth, top + titleHeight);
	} else {
		child.offsetLeftAndRight(left - child.getLeft());
		child.offsetTopAndBottom(top - child.getTop());
	}
}
 
Example 12
Source File: MarginDrawerLayout.java    From something.apk with MIT License 5 votes vote down vote up
void moveDrawerToOffset(View drawerView, float slideOffset) {
    final float oldOffset = getDrawerViewOffset(drawerView);
    final int width = drawerView.getWidth();
    final int oldPos = (int) (width * oldOffset);
    final int newPos = (int) (width * slideOffset);
    final int dx = newPos - oldPos;

    drawerView.offsetLeftAndRight(
            checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT) ? dx : -dx);
    setDrawerViewOffset(drawerView, slideOffset);
}
 
Example 13
Source File: DrawerLayout.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
void c(View view, float f1)
{
    float f2 = c(view);
    int i1 = view.getWidth();
    int j1 = (int)(f2 * (float)i1);
    int k1 = (int)(f1 * (float)i1) - j1;
    if (!a(view, 3))
    {
        k1 = -k1;
    }
    view.offsetLeftAndRight(k1);
    b(view, f1);
}
 
Example 14
Source File: ViewCompat.java    From SmartSwipe with Apache License 2.0 5 votes vote down vote up
/**
 * Offset this view's horizontal location by the specified amount of pixels.
 *
 * @param view view
 * @param offset the number of pixels to offset the view by
 */
public static void offsetLeftAndRight(View view, int offset) {
    if (view == null || offset == 0) {
        return;
    }
    if (Build.VERSION.SDK_INT >= 23) {
        view.offsetLeftAndRight(offset);
    } else if (Build.VERSION.SDK_INT >= 21) {
        final Rect parentRect = getEmptyTempRect();
        boolean needInvalidateWorkaround = false;

        final ViewParent parent = view.getParent();
        if (parent instanceof View) {
            final View p = (View) parent;
            parentRect.set(p.getLeft(), p.getTop(), p.getRight(), p.getBottom());
            // If the view currently does not currently intersect the parent (and is therefore
            // not displayed) we may need need to invalidate
            needInvalidateWorkaround = !parentRect.intersects(view.getLeft(), view.getTop(),
                    view.getRight(), view.getBottom());
        }

        // Now offset, invoking the API 14+ implementation (which contains its own workarounds)
        compatOffsetLeftAndRight(view, offset);

        // The view has now been offset, so let's intersect the Rect and invalidate where
        // the View is now displayed
        if (needInvalidateWorkaround && parentRect.intersect(view.getLeft(), view.getTop(),
                view.getRight(), view.getBottom())) {
            ((View) parent).invalidate(parentRect);
        }
    } else {
        compatOffsetLeftAndRight(view, offset);
    }
}
 
Example 15
Source File: DebugDrawerLayout.java    From u2020 with Apache License 2.0 5 votes vote down vote up
void moveDrawerToOffset(View drawerView, float slideOffset) {
  final float oldOffset = getDrawerViewOffset(drawerView);
  final int width = drawerView.getWidth();
  final int oldPos = (int) (width * oldOffset);
  final int newPos = (int) (width * slideOffset);
  final int dx = newPos - oldPos;

  drawerView.offsetLeftAndRight(
      checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT) ? dx : -dx);
  setDrawerViewOffset(drawerView, slideOffset);
}
 
Example 16
Source File: HListView.java    From letv with Apache License 2.0 4 votes vote down vote up
private View moveSelection(View oldSel, View newSel, int delta, int childrenLeft, int childrenRight) {
    View sel;
    int fadingEdgeLength = getHorizontalFadingEdgeLength();
    int selectedPosition = this.mSelectedPosition;
    int leftSelectionPixel = getLeftSelectionPixel(childrenLeft, fadingEdgeLength, selectedPosition);
    int rightSelectionPixel = getRightSelectionPixel(childrenLeft, fadingEdgeLength, selectedPosition);
    int halfHorizontalSpace;
    if (delta > 0) {
        oldSel = makeAndAddView(selectedPosition - 1, oldSel.getLeft(), true, this.mListPadding.top, false);
        int dividerWidth = this.mDividerWidth;
        sel = makeAndAddView(selectedPosition, oldSel.getRight() + dividerWidth, true, this.mListPadding.top, true);
        if (sel.getRight() > rightSelectionPixel) {
            halfHorizontalSpace = (childrenRight - childrenLeft) / 2;
            int offset = Math.min(Math.min(sel.getLeft() - leftSelectionPixel, sel.getRight() - rightSelectionPixel), halfHorizontalSpace);
            oldSel.offsetLeftAndRight(-offset);
            sel.offsetLeftAndRight(-offset);
        }
        if (this.mStackFromRight) {
            fillRight(this.mSelectedPosition + 1, sel.getRight() + dividerWidth);
            adjustViewsLeftOrRight();
            fillLeft(this.mSelectedPosition - 2, sel.getLeft() - dividerWidth);
        } else {
            fillLeft(this.mSelectedPosition - 2, sel.getLeft() - dividerWidth);
            adjustViewsLeftOrRight();
            fillRight(this.mSelectedPosition + 1, sel.getRight() + dividerWidth);
        }
    } else if (delta < 0) {
        if (newSel != null) {
            sel = makeAndAddView(selectedPosition, newSel.getLeft(), true, this.mListPadding.top, true);
        } else {
            sel = makeAndAddView(selectedPosition, oldSel.getLeft(), false, this.mListPadding.top, true);
        }
        if (sel.getLeft() < leftSelectionPixel) {
            halfHorizontalSpace = (childrenRight - childrenLeft) / 2;
            View view = sel;
            view.offsetLeftAndRight(Math.min(Math.min(leftSelectionPixel - sel.getLeft(), rightSelectionPixel - sel.getRight()), halfHorizontalSpace));
        }
        fillBeforeAndAfter(sel, selectedPosition);
    } else {
        int oldLeft = oldSel.getLeft();
        sel = makeAndAddView(selectedPosition, oldLeft, true, this.mListPadding.top, true);
        if (oldLeft < childrenLeft && sel.getRight() < childrenLeft + 20) {
            sel.offsetLeftAndRight(childrenLeft - sel.getLeft());
        }
        fillBeforeAndAfter(sel, selectedPosition);
    }
    return sel;
}
 
Example 17
Source File: SlideLayout.java    From SlideLayout with GNU General Public License v2.0 4 votes vote down vote up
private void offsetLeftAndRight(View v, int offset){
   	if(v == null)
   		return;
   	
	v.offsetLeftAndRight(offset);
}
 
Example 18
Source File: PLAListView.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
protected void onOffsetChild(View child, int position, int offsetLeft, int offsetTop) {
    child.offsetLeftAndRight(offsetLeft);
    child.offsetTopAndBottom(offsetTop);
}
 
Example 19
Source File: VelocityViewPager.java    From Rey-MusicPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 * @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;
}
 
Example 20
Source File: VelocityViewPager.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 * @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;
}