本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}