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

The following examples show how to use android.view.View#offsetTopAndBottom() . These examples are extracted from open source projects. 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
private float performDrag(float dy) {
    final float newPos = Math.max(0, Math.min(mCollapseOffset + dy, mCollapsibleHeight));
    if (newPos != mCollapseOffset) {
        dy = newPos - mCollapseOffset;
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.ignoreOffset) {
                child.offsetTopAndBottom((int) dy);
            }
        }
        mCollapseOffset = newPos;
        mTopOffset += dy;
        ViewCompat.postInvalidateOnAnimation(this);
        return dy;
    }
    return 0;
}
 
Example 2
protected void offsetChildrenTopAndBottom(final int offset, final int column) {
    if (DBG) Log.d(TAG, "offsetChildrenTopAndBottom: " + offset + " column:" + column);
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View v = getChildAt(i);
        if (v != null &&
                v.getLayoutParams() != null &&
                v.getLayoutParams() instanceof GridLayoutParams) {
            GridLayoutParams lp = (GridLayoutParams) v.getLayoutParams();
            if (lp.column == column) {
                v.offsetTopAndBottom(offset);
            }
        }
    }
    offsetColumnTopAndBottom(offset, column);
}
 
Example 3
Source Project: EverMemo   File: MultiColumnListView.java    License: MIT License 6 votes vote down vote up
public void offsetTopAndBottom(int offset) {
	if( offset == 0 )
		return; 

	//find biggest value.
	int childCount = getChildCount();

	for( int index = 0; index < childCount; ++index ){
		View v = getChildAt(index);

		if(v.getLeft() != mColumnLeft && isFixedView(v) == false )
			continue;

		v.offsetTopAndBottom(offset);
	}
}
 
Example 4
private void adjustChildrenOfUnderTopView(float scrollRate) {
    int count = getChildCount();
    if (count > 1) {
        int i;
        int multiple;
        if (count == 2) {
            i = LAST_VIEW_IN_STACK - 1;
            multiple = 1;
        } else {
            i = LAST_VIEW_IN_STACK - 2;
            multiple = 2;
        }
        float rate = Math.abs(scrollRate);
        for (; i < LAST_VIEW_IN_STACK; i++, multiple--) {
            View underTopView = getChildAt(i);
            int offset = (int) (yOffsetStep * (multiple - rate));
            underTopView.offsetTopAndBottom(offset - underTopView.getTop() + initTop);
            underTopView.setScaleX(1 - SCALE_STEP * multiple + SCALE_STEP * rate);
            underTopView.setScaleY(1 - SCALE_STEP * multiple + SCALE_STEP * rate);
        }
    }
}
 
Example 5
private void parallaxOtherViews(float slideOffset) {
    final LayoutParams slideLp = (LayoutParams) mSlideableView.getLayoutParams();
    final boolean dimViews = slideLp.dimWhenOffset &&
            slideLp.topMargin <= 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 dy = oldOffset - newOffset;

        v.offsetTopAndBottom(dy);

        if (dimViews) {
            dimChildView(v, 1 - mParallaxOffset, mCoveredFadeColor);
        }
    }
}
 
Example 6
Source Project: ZrcListView   File: ZrcAbsListView.java    License: MIT License 5 votes vote down vote up
public void offsetChildrenTopAndBottom(int offset) {
	final int count = getChildCount();
	for (int i = 0; i < count; i++) {
		final View v = getChildAt(i);
		v.offsetTopAndBottom(offset);
	}
}
 
Example 7
protected void offsetChildrenTopAndBottom(int offset) {
    if (DBG) Log.d(TAG, "offsetChildrenTopAndBottom: " + offset);
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View v = getChildAt(i);
        v.offsetTopAndBottom(offset);
    }
}
 
Example 8
private void adjustChildView(View child, int index) {
    if (index > -1 && index < MAX_VISIBLE) {
        int multiple;
        if (index > 2) multiple = 2;
        else multiple = index;
        child.offsetTopAndBottom(yOffsetStep * multiple);
        child.setScaleX(1 - SCALE_STEP * multiple);
        child.setScaleY(1 - SCALE_STEP * multiple);
    }
}
 
Example 9
Source Project: Social   File: SwipeFlingAdapterView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 跳转改变view 大小
 *
 * @param child
 * @param index
 */
private void adjustChildView(View child, int index) {
    int n;
    if (index > 1)
        n = 2;
    else
        n = index;
    if (index == 3 && p > 0.5f) {
        n = index;
    }
    child.offsetTopAndBottom((int) (dpToPx((int) ITEM_SMALL_HIGH) * (n - p)));
    child.setScaleX(1 - 0.1f * (n - p));
    child.setScaleY(1 - 0.1f * (n - p));
}
 
Example 10
private void moveHandle(int position) {
	final View handle = mHandle;

	if (position == EXPANDED_FULL_OPEN) {
		handle.offsetTopAndBottom(mTopOffset - handle.getTop());
		invalidate();
	} else if (position == COLLAPSED_FULL_CLOSED) {
		handle.offsetTopAndBottom(mBottomOffset + getBottom() - getTop() - mHandleHeight - handle.getTop());
		invalidate();
	} else {
		final int top = handle.getTop();
		int deltaY = position - top;
		if (position < mTopOffset) {
			deltaY = mTopOffset - top;
		} else if (deltaY > mBottomOffset + getBottom() - getTop() - mHandleHeight - top) {
			deltaY = mBottomOffset + getBottom() - getTop() - mHandleHeight - top;
		}
		handle.offsetTopAndBottom(deltaY);

		final Rect frame = mFrame;
		final Rect region = mInvalidate;

		handle.getHitRect(frame);
		region.set(frame);

		region.union(frame.left, frame.top - deltaY, frame.right, frame.bottom - deltaY);
		region.union(0, frame.bottom - deltaY, getWidth(), frame.bottom - deltaY + mContent.getHeight());

		invalidate(region);
	}
}
 
Example 11
Source Project: Lay-s   File: PLAAbsListView.java    License: MIT License 5 votes vote down vote up
protected void tryOffsetChildrenTopAndBottom(int offset) {
    final int count = getChildCount();

    for (int i = 0; i < count; i++) {
        final View v = getChildAt(i);
        v.offsetTopAndBottom(offset);
    }
}
 
Example 12
Source Project: ticdesign   File: CoordinatorLayout.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adjust the child left, top, right, bottom rect to the correct anchor view position,
 * respecting gravity and anchor gravity.
 *
 * Note that child translation properties are ignored in this process, allowing children
 * to be animated away from their anchor. However, if the anchor view is animated,
 * the child will be offset to match the anchor's translated position.
 */
void offsetChildToAnchor(View child, int layoutDirection) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    if (lp.mAnchorView != null) {
        final Rect anchorRect = mTempRect1;
        final Rect childRect = mTempRect2;
        final Rect desiredChildRect = mTempRect3;

        getDescendantRect(lp.mAnchorView, anchorRect);
        getChildRect(child, false, childRect);
        getDesiredAnchoredChildRect(child, layoutDirection, anchorRect, desiredChildRect);

        final int dx = desiredChildRect.left - childRect.left;
        final int dy = desiredChildRect.top - childRect.top;

        if (dx != 0) {
            child.offsetLeftAndRight(dx);
        }
        if (dy != 0) {
            child.offsetTopAndBottom(dy);
        }

        if (dx != 0 || dy != 0) {
            // If we have needed to move, make sure to notify the child's Behavior
            final Behavior b = lp.getBehavior();
            if (b != null) {
                b.onDependentViewChanged(this, child, lp.mAnchorView);
            }
        }
    }
}
 
Example 13
Source Project: Lay-s   File: PLAListView.java    License: MIT License 4 votes vote down vote up
protected void onOffsetChild(View child, int position, int offsetLeft, int offsetTop) {
    child.offsetLeftAndRight(offsetLeft);
    child.offsetTopAndBottom(offsetTop);
}
 
Example 14
private void handleActionMove(MotionEvent event) {
    if (!isPanelOnTouch) {
        return;
    }
    if (isPanelShowing && supportScrollInView((int) (firstDownY - event.getY()))) {
        return;
    }
    computeVelocity();
    if (Math.abs(xVelocity) > Math.abs(yVelocity)) {
        return;
    }
    if (!isDragging && Math.abs(event.getY() - firstDownY) > mTouchSlop
            && Math.abs(event.getX() - firstDownX) < mTouchSlop) {
        isDragging = true;
        downY = event.getY();
    }
    if (isDragging) {
        deltaY = event.getY() - downY;
        downY = event.getY();

        View touchingView = findViewWithTag(TAG_PANEL);

        if (mHidePanelTitle && isPanelShowing) {
            hidePanelTitle(touchingView);
        }

        if (mDarkFrameLayout != null && mIsFade) {
            float currentY = ViewHelper.getY(touchingView);
            if (currentY > mMeasureHeight - mPanelHeight &&
                    currentY < mMeasureHeight - mTitleHeightNoDisplay) {
                mDarkFrameLayout.fade(
                        (int) ((1 - currentY / (mMeasureHeight - mTitleHeightNoDisplay)) * DarkFrameLayout.MAX_ALPHA));
            }
        }
        if (!mBoundary) {
            touchingView.offsetTopAndBottom((int) deltaY);
        } else {
            float touchingViewY = ViewHelper.getY(touchingView);
            if (touchingViewY + deltaY <= mMeasureHeight - mPanelHeight) {
                touchingView.offsetTopAndBottom((int) (mMeasureHeight - mPanelHeight - touchingViewY));
            } else if (touchingViewY + deltaY >= mMeasureHeight - mTitleHeightNoDisplay) {
                touchingView.offsetTopAndBottom((int) (mMeasureHeight - mTitleHeightNoDisplay - touchingViewY));
            } else {
                touchingView.offsetTopAndBottom((int) deltaY);
            }
        }
    }
}
 
Example 15
protected void translatePreICS(View view, float f1)
{
    view.offsetTopAndBottom((int)f1 - lastOffset);
    lastOffset = (int)f1;
}
 
Example 16
@Override
public void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);

    final boolean hasTabs = mTabContainer != null && mTabContainer.getVisibility() != GONE;

    if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
        final int containerHeight = getMeasuredHeight();
        final int tabHeight = mTabContainer.getMeasuredHeight();

        if ((mActionBarView.getDisplayOptions() & ActionBar.DISPLAY_SHOW_HOME) == 0) {
            // Not showing home, put tabs on top.
            final int count = getChildCount();
            for (int i = 0; i < count; i++) {
                final View child = getChildAt(i);

                if (child == mTabContainer) continue;

                if (!mActionBarView.isCollapsed()) {
                    child.offsetTopAndBottom(tabHeight);
                }
            }
            mTabContainer.layout(l, 0, r, tabHeight);
        } else {
            mTabContainer.layout(l, containerHeight - tabHeight, r, containerHeight);
        }
    }

    boolean needsInvalidate = false;
    if (mIsSplit) {
        if (mSplitBackground != null) {
            mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
            needsInvalidate = true;
        }
    } else {
        if (mBackground != null) {
            mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(),
                    mActionBarView.getRight(), mActionBarView.getBottom());
            needsInvalidate = true;
        }
        if ((mIsStacked = hasTabs && mStackedBackground != null)) {
            mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(),
                    mTabContainer.getRight(), mTabContainer.getBottom());
            needsInvalidate = true;
        }
    }

    if (needsInvalidate) {
        invalidate();
    }
}
 
Example 17
Source Project: letv   File: HListView.java    License: Apache License 2.0 4 votes vote down vote up
@TargetApi(11)
private void setupChild(View child, int position, int x, boolean flowDown, int childrenTop, boolean selected, boolean recycled) {
    boolean isSelected = selected && shouldShowSelector();
    boolean updateChildSelected = isSelected != child.isSelected();
    int mode = this.mTouchMode;
    boolean isPressed = mode > 0 && mode < 3 && this.mMotionPosition == position;
    boolean updateChildPressed = isPressed != child.isPressed();
    boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (LayoutParams) generateDefaultLayoutParams();
    }
    p.viewType = this.mAdapter.getItemViewType(position);
    if ((!recycled || p.forceAdd) && !(p.recycledHeaderFooter && p.viewType == -2)) {
        p.forceAdd = false;
        if (p.viewType == -2) {
            p.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, p, true);
    } else {
        attachViewToParent(child, flowDown ? -1 : 0, p);
    }
    if (updateChildSelected) {
        child.setSelected(isSelected);
    }
    if (updateChildPressed) {
        child.setPressed(isPressed);
    }
    if (!(this.mChoiceMode == 0 || this.mCheckStates == null)) {
        if (child instanceof Checkable) {
            ((Checkable) child).setChecked(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        } else if (VERSION.SDK_INT >= 11) {
            child.setActivated(((Boolean) this.mCheckStates.get(position, Boolean.valueOf(false))).booleanValue());
        }
    }
    if (needToMeasure) {
        int childWidthSpec;
        int childHeightSpec = ViewGroup.getChildMeasureSpec(this.mHeightMeasureSpec, this.mListPadding.top + this.mListPadding.bottom, p.height);
        int lpWidth = p.width;
        if (lpWidth > 0) {
            childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, 1073741824);
        } else {
            childWidthSpec = MeasureSpec.makeMeasureSpec(0, 0);
        }
        child.measure(childWidthSpec, childHeightSpec);
    } else {
        cleanupLayoutState(child);
    }
    int w = child.getMeasuredWidth();
    int h = child.getMeasuredHeight();
    int childLeft = flowDown ? x : x - w;
    if (needToMeasure) {
        child.layout(childLeft, childrenTop, childLeft + w, childrenTop + h);
    } else {
        child.offsetLeftAndRight(childLeft - child.getLeft());
        child.offsetTopAndBottom(childrenTop - child.getTop());
    }
    if (this.mCachingStarted && !child.isDrawingCacheEnabled()) {
        child.setDrawingCacheEnabled(true);
    }
    if (VERSION.SDK_INT >= 11 && recycled && ((LayoutParams) child.getLayoutParams()).scrappedFromPosition != position) {
        child.jumpDrawablesToCurrentState();
    }
}
 
Example 18
Source Project: ParallaxScroll   File: ParallaxScrollView.java    License: MIT License 4 votes vote down vote up
@Override
protected void translatePreICS(View view, float offset) {
	view.offsetTopAndBottom((int)offset - lastOffset);
	lastOffset = (int)offset;
}
 
Example 19
protected void translatePreICS(View view, float f)
{
    view.offsetTopAndBottom((int)f - lastOffset);
    lastOffset = (int)f;
}
 
Example 20
Source Project: material   File: BottomSheetDialog.java    License: Apache License 2.0 4 votes vote down vote up
public void setChildTop(int top){
    mChildTop = top;
    View child = getChildAt(0);
    if(child != null)
        child.offsetTopAndBottom(mChildTop - child.getTop());
}