當前位置: 首頁>>代碼示例>>Java>>正文


Java ViewCompat.offsetTopAndBottom方法代碼示例

本文整理匯總了Java中android.support.v4.view.ViewCompat.offsetTopAndBottom方法的典型用法代碼示例。如果您正苦於以下問題:Java ViewCompat.offsetTopAndBottom方法的具體用法?Java ViewCompat.offsetTopAndBottom怎麽用?Java ViewCompat.offsetTopAndBottom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.view.ViewCompat的用法示例。


在下文中一共展示了ViewCompat.offsetTopAndBottom方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onNestedPreScroll

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
/**
 * 當子View開始滾動之前, 你可以通過此方法消耗掉滾動事件, 並偏移child的位置
 */
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed) {
    if (dy == 0 || (dy < 0 && ViewCompat.canScrollVertically(target, -1))) {
        return;
    }

    int offsetMax = mTargetView.getMeasuredHeight() - stickHeight;

    int top = mTargetView.getTop();
    int offset = 0;
    if (dy > 0) {
        //上滑
        offset = Math.min(dy, offsetMax + top);
    } else if (dy < 0) {
        //下滑
        offset = Math.max(dy, top);
    }
    ViewCompat.offsetTopAndBottom(mTargetView, -offset);
    consumed[1] = offset;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:24,代碼來源:StickBehavior.java

示例2: dragTo

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
private void dragTo(int left, int top, int dx, int dy) {
    int clampedX = left;
    int clampedY = top;
    int oldLeft = this.mCapturedView.getLeft();
    int oldTop = this.mCapturedView.getTop();
    if (dx != 0) {
        clampedX = this.mCallback.clampViewPositionHorizontal(this.mCapturedView, left, dx);
        ViewCompat.offsetLeftAndRight(this.mCapturedView, clampedX - oldLeft);
    }
    if (dy != 0) {
        clampedY = this.mCallback.clampViewPositionVertical(this.mCapturedView, top, dy);
        ViewCompat.offsetTopAndBottom(this.mCapturedView, clampedY - oldTop);
    }
    if (dx != 0 || dy != 0) {
        this.mCallback.onViewPositionChanged(this.mCapturedView, clampedX, clampedY, clampedX - oldLeft, clampedY - oldTop);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:ViewDragHelper.java

示例3: onNestedPreScroll

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
@Override
  public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx,
          int dy, int[] consumed) {
  View scrollingChild = mNestedScrollingChildRef.get();
  if (target != scrollingChild) {
    return;
  }
  int currentTop = child.getTop();
  int newTop = currentTop - dy;
  if (dy > 0) { // Upward
    if (newTop < mMinOffset) {
      consumed[1] = currentTop - mMinOffset;
      ViewCompat.offsetTopAndBottom(child, -consumed[1]);
      setStateInternal(STATE_EXPANDED);
    } else {
      consumed[1] = dy;
      ViewCompat.offsetTopAndBottom(child, -dy);
      setStateInternal(STATE_DRAGGING);
    }
  } else if (dy < 0) { // Downward
          if (!target.canScrollVertically(-1)) {
      if (newTop <= mMaxOffset || mHideable) {
        consumed[1] = dy;
        ViewCompat.offsetTopAndBottom(child, -dy);
        setStateInternal(STATE_DRAGGING);
      } else {
        consumed[1] = currentTop - mMaxOffset;
        ViewCompat.offsetTopAndBottom(child, -consumed[1]);
        setStateInternal(STATE_COLLAPSED);
      }
    }
  }
  dispatchOnSlide(child.getTop());
  mLastNestedScrollDy = dy;
  mNestedScrolled = true;
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:37,代碼來源:BottomSheetBehavior.java

示例4: onNestedPreScroll

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
/**
 * 當子View開始滾動之前, 你可以通過此方法消耗掉滾動事件, 並偏移child的位置
 */
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed) {
    if (dy == 0 || (dy < 0 && ViewCompat.canScrollVertically(target, -1))) {
        return;
    }

    int offsetMax = mTargetView.getMeasuredHeight() - stickHeight - stickOffset;

    int top = mTargetView.getTop();
    int offset = 0;
    if (dy > 0) {
        //上滑
        offset = Math.min(dy, offsetMax + top);
    } else if (dy < 0) {
        //下滑
        offset = Math.max(dy, top);
    }
    ViewCompat.offsetTopAndBottom(mTargetView, -offset);
    consumed[1] = offset;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:24,代碼來源:StickBehavior2.java

示例5: onLayoutChild

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
        ViewCompat.setFitsSystemWindows(child, true);
    }
    int savedTop = child.getTop();
    // First let the parent lay it out
    parent.onLayoutChild(child, layoutDirection);
    // Offset the bottom sheet
    mParentHeight = parent.getHeight();
    int peekHeight;
    if (mPeekHeightAuto) {
        if (mPeekHeightMin == 0) {
            mPeekHeightMin = parent.getResources().getDimensionPixelSize(
                    R.dimen.design_bottom_sheet_peek_height_min);
        }
        peekHeight = Math.max(mPeekHeightMin, mParentHeight - parent.getWidth() * 9 / 16);
    } else {
        peekHeight = mPeekHeight;
    }
    mMinOffset = Math.max(0, mParentHeight - child.getHeight());
    mMaxOffset = Math.max(mParentHeight - peekHeight, mMinOffset);
    if (mState == STATE_EXPANDED) {
        ViewCompat.offsetTopAndBottom(child, mMinOffset);
    } else if (mHideable && mState == STATE_HIDDEN) {
        ViewCompat.offsetTopAndBottom(child, mParentHeight);
    } else if (mState == STATE_COLLAPSED) {
        ViewCompat.offsetTopAndBottom(child, mMaxOffset);
    } else if (mState == STATE_DRAGGING || mState == STATE_SETTLING) {
        ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop());
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}
 
開發者ID:Krupen,項目名稱:FabulousFilter,代碼行數:39,代碼來源:ViewPagerBottomSheetBehavior.java

示例6: setTargetOffsetTopAndBottom

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
private void setTargetOffsetTopAndBottom(int offset, boolean requiresUpdate) {
    if (mRefreshView == null) {
        ensureTarget();
    }
    mRefreshView.bringToFront();
    ViewCompat.offsetTopAndBottom(mRefreshView, offset);
    mCurrentTargetOffsetTop = mRefreshView.getTop();
    if (requiresUpdate && android.os.Build.VERSION.SDK_INT < 11) {
        invalidate();
    }
}
 
開發者ID:Bvin,項目名稱:gesture-refresh-layout,代碼行數:12,代碼來源:GestureRefreshLayout.java

示例7: continueSettling

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
/**
 * Move the captured settling view by the appropriate amount for the current time.
 * If <code>continueSettling</code> returns true, the caller should call it again
 * on the next frame to continue.
 *
 * @param deferCallbacks true if state callbacks should be deferred via posted message.
 *                       Set this to true if you are calling this method from
 *                       {@link android.view.View#computeScroll()} or similar methods
 *                       invoked as part of layout or drawing.
 * @return true if settle is still in progress
 */
public boolean continueSettling(boolean deferCallbacks) {
    if (mDragState == STATE_SETTLING) {
        boolean keepGoing = mScroller.computeScrollOffset();
        final int x = mScroller.getCurrX();
        final int y = mScroller.getCurrY();
        final int dx = (int) (x - mCapturedView.getX());
        final int dy = (int) (y - mCapturedView.getY());

        if (dx != 0) {
            ViewCompat.offsetLeftAndRight(mCapturedView, dx);
        }
        if (dy != 0) {
            ViewCompat.offsetTopAndBottom(mCapturedView, dy);
        }

        if (dx != 0 || dy != 0) {
            mCallback.onViewPositionChanged(mCapturedView, x, y, dx, dy);
        }

        if (keepGoing && x == mScroller.getFinalX() && y == mScroller.getFinalY()) {
            // Close enough. The interpolator/scroller might think we're still moving
            // but the user sure doesn't.
            mScroller.abortAnimation();
            keepGoing = false;
        }

        if (!keepGoing) {
            if (deferCallbacks) {
                mParentView.post(mSetIdleRunnable);
            } else {
                setDragState(STATE_IDLE);
            }
        }
    }

    return mDragState == STATE_SETTLING;
}
 
開發者ID:Kaufland,項目名稱:andswipeframework,代碼行數:49,代碼來源:KDragViewHelper.java

示例8: updateOffsets

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
private void updateOffsets() {
    ViewCompat.offsetTopAndBottom(mView, mOffsetTop - (mView.getTop() - mLayoutTop));
    ViewCompat.offsetLeftAndRight(mView, mOffsetLeft - (mView.getLeft() - mLayoutLeft));

    // Manually invalidate the view and parent to make sure we get drawn pre-M
    if (Build.VERSION.SDK_INT < 23) {
        tickleInvalidationFlag(mView);
        final ViewParent vp = mView.getParent();
        if (vp instanceof View) {
            tickleInvalidationFlag((View) vp);
        }
    }
}
 
開發者ID:zuoni1018,項目名稱:CoordinatorLayoutExample-master,代碼行數:14,代碼來源:ViewOffsetHelper.java

示例9: moveTargetViewTo

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
private int moveTargetViewTo(int target, boolean isDragging, boolean calculateAnyWay) {
    target = Math.max(target, mTargetInitOffset);
    if (!mEnableOverPull) {
        target = Math.min(target, mTargetRefreshOffset);
    }
    int offset = 0;
    if (target != mTargetCurrentOffset || calculateAnyWay) {
        offset = target - mTargetCurrentOffset;
        ViewCompat.offsetTopAndBottom(mTargetView, offset);
        mTargetCurrentOffset = target;
        int total = mTargetRefreshOffset - mTargetInitOffset;
        if (isDragging) {
            mIRefreshView.onPull(Math.min(mTargetCurrentOffset - mTargetInitOffset, total), total,
                    mTargetCurrentOffset - mTargetRefreshOffset);
        }
        onMoveTargetView(mTargetCurrentOffset);
        if (mListener != null) {
            mListener.onMoveTarget(mTargetCurrentOffset);
        }

        if (mRefreshOffsetCalculator == null) {
            mRefreshOffsetCalculator = new QMUIDefaultRefreshOffsetCalculator();
        }
        int newRefreshOffset = mRefreshOffsetCalculator.calculateRefreshOffset(mRefreshInitOffset, mRefreshEndOffset, mRefreshView.getHeight(),
                mTargetCurrentOffset, mTargetInitOffset, mTargetRefreshOffset);
        if (newRefreshOffset != mRefreshCurrentOffset) {
            ViewCompat.offsetTopAndBottom(mRefreshView, newRefreshOffset - mRefreshCurrentOffset);
            mRefreshCurrentOffset = newRefreshOffset;
            onMoveRefreshView(mRefreshCurrentOffset);
            if (mListener != null) {
                mListener.onMoveRefreshView(mRefreshCurrentOffset);
            }
        }
    }
    return offset;
}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:37,代碼來源:QMUIPullRefreshLayout.java

示例10: onDependentViewChanged

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
/**
 * 當被監聽的view發生改變時回調
 * 可以在此方法裏麵做一些響應的聯動動畫等效果
 */
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    int offset = dependency.getTop() - child.getTop();
    ViewCompat.offsetTopAndBottom(child, offset);
    return super.onDependentViewChanged(parent, child, dependency);
}
 
開發者ID:GitLqr,項目名稱:MaterialDesignDemo,代碼行數:11,代碼來源:CustomerBehavior1.java

示例11: setInsetOffsetY

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
private void setInsetOffsetY(View child, int offsetY) {
  final LayoutParams lp = (LayoutParams) child.getLayoutParams();
  if (lp.mInsetOffsetY != offsetY) {
    final int dy = offsetY - lp.mInsetOffsetY;
    ViewCompat.offsetTopAndBottom(child, dy);
    lp.mInsetOffsetY = offsetY;
  }
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:9,代碼來源:CoordinatorLayout.java

示例12: onLayoutChild

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
/**
 * 布局child的位置, 和自定義view的套路一樣
 */
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    if (mTargetView != null) {
        ViewCompat.offsetTopAndBottom(mTargetView, lastTop);
        int top = mTargetView.getBottom();// - Math.abs(lastTop);
        child.layout(0, top, child.getMeasuredWidth(), top + child.getMeasuredHeight());
        return true;
    }
    return super.onLayoutChild(parent, child, layoutDirection);
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:14,代碼來源:StickBehavior.java

示例13: moveViews

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
/**
 * 移動view
 *
 * @param dy 要移動的距離
 */
private void moveViews(int dy)
{
    if (getDirection() == Direction.FROM_HEADER)
    {
        if (mIsOverLayMode)
        {
            //覆蓋模式
            if (ViewCompat.getZ(mHeaderView) <= ViewCompat.getZ(mRefreshView))
            {
                ViewCompat.setZ(mHeaderView, ViewCompat.getZ(mRefreshView) + 1);
            }
        } else
        {
            ViewCompat.offsetTopAndBottom(mRefreshView, dy);
        }
        mHeaderView.onViewPositionChanged(this);
    } else
    {
        if (mIsOverLayMode)
        {
            //覆蓋模式
            if (ViewCompat.getZ(mFooterView) <= ViewCompat.getZ(mRefreshView))
            {
                ViewCompat.setZ(mFooterView, ViewCompat.getZ(mRefreshView) + 1);
            }
        } else
        {
            ViewCompat.offsetTopAndBottom(mRefreshView, dy);
        }
        mFooterView.onViewPositionChanged(this);
    }

    if (mOnViewPositionChangedCallback != null)
    {
        mOnViewPositionChangedCallback.onViewPositionChanged(this);
    }
}
 
開發者ID:zj565061763,項目名稱:pulltorefresh,代碼行數:43,代碼來源:FPullToRefreshView.java

示例14: continueSettling

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
public boolean continueSettling(boolean deferCallbacks) {
    if (this.mDragState == 2) {
        boolean keepGoing = this.mScroller.computeScrollOffset();
        int x = this.mScroller.getCurrX();
        int y = this.mScroller.getCurrY();
        int dx = x - this.mCapturedView.getLeft();
        int dy = y - this.mCapturedView.getTop();
        if (dx != 0) {
            ViewCompat.offsetLeftAndRight(this.mCapturedView, dx);
        }
        if (dy != 0) {
            ViewCompat.offsetTopAndBottom(this.mCapturedView, dy);
        }
        if (!(dx == 0 && dy == 0)) {
            this.mCallback.onViewPositionChanged(this.mCapturedView, x, y, dx, dy);
        }
        if (keepGoing && x == this.mScroller.getFinalX() && y == this.mScroller.getFinalY()) {
            this.mScroller.abortAnimation();
            keepGoing = false;
        }
        if (!keepGoing) {
            if (deferCallbacks) {
                this.mParentView.post(this.mSetIdleRunnable);
            } else {
                setDragState(0);
            }
        }
    }
    return this.mDragState == 2;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:31,代碼來源:ViewDragHelper.java

示例15: onNestedPreScroll

import android.support.v4.view.ViewCompat; //導入方法依賴的package包/類
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed) {
    View scrollingChild = mNestedScrollingChildRef.get();
    if (target != scrollingChild) {
        return;
    }

    mScrollVelocityTracker.recordScroll(dy);

    int currentTop = child.getTop();
    int newTop = currentTop - dy;

    // Force stop at the anchor - do not go from collapsed to expanded in one scroll
    if (
            (mLastStableState == STATE_COLLAPSED && newTop < mAnchorPoint) ||
                    (mLastStableState == STATE_EXPANDED && newTop > mAnchorPoint)
            ) {
        consumed[1] = dy;
        ViewCompat.offsetTopAndBottom(child, mAnchorPoint - currentTop);
        dispatchOnSlide(child.getTop());
        mNestedScrolled = true;
        return;
    }

    if (dy > 0) { // Upward
        if (newTop < mMinOffset) {
            consumed[1] = currentTop - mMinOffset;
            ViewCompat.offsetTopAndBottom(child, -consumed[1]);
            setStateInternal(STATE_EXPANDED);
        } else {
            consumed[1] = dy;
            ViewCompat.offsetTopAndBottom(child, -dy);
            setStateInternal(STATE_DRAGGING);
        }
    } else if (dy < 0) { // Downward
        if (!ViewCompat.canScrollVertically(target, -1)) {
            if (newTop <= mMaxOffset || mHideable) {
                consumed[1] = dy;
                ViewCompat.offsetTopAndBottom(child, -dy);
                setStateInternal(STATE_DRAGGING);
            } else {
                consumed[1] = currentTop - mMaxOffset;
                ViewCompat.offsetTopAndBottom(child, -consumed[1]);
                setStateInternal(STATE_COLLAPSED);
            }
        }
    }
    dispatchOnSlide(child.getTop());
    mNestedScrolled = true;
}
 
開發者ID:aliumujib,項目名稱:Nibo,代碼行數:51,代碼來源:BottomSheetBehaviorGoogleMapsLike.java


注:本文中的android.support.v4.view.ViewCompat.offsetTopAndBottom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。