static void setScrollY(View view, int scrollY) { view.setScrollY(scrollY); }
@Nullable @Override public Animator createAnimator(@NonNull ViewGroup sceneRoot, @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) { if (startValues == null || endValues == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { return null; } final View view = endValues.view; int startX = (Integer) startValues.values.get(PROPNAME_SCROLL_X); int endX = (Integer) endValues.values.get(PROPNAME_SCROLL_X); int startY = (Integer) startValues.values.get(PROPNAME_SCROLL_Y); int endY = (Integer) endValues.values.get(PROPNAME_SCROLL_Y); Animator scrollXAnimator = null; Animator scrollYAnimator = null; if (startX != endX) { view.setScrollX(startX); scrollXAnimator = ObjectAnimator.ofInt(view, "scrollX", startX, endX); } if (startY != endY) { view.setScrollY(startY); scrollYAnimator = ObjectAnimator.ofInt(view, "scrollY", startY, endY); } return TransitionUtils.mergeAnimators(scrollXAnimator, scrollYAnimator); } }
@Test public void setScrolls_canBeAskedFor() throws Exception { view.setScrollX(234); view.setScrollY(544); assertThat(view.getScrollX()).isEqualTo(234); assertThat(view.getScrollY()).isEqualTo(544); }
static void setScrollY(View view, int scrollY) { view.setScrollY(scrollY); }
@Override public void transformPage(View page, float position) { page.setScrollY(100); ... }
@Override public void setScrollY(View view, int scrollY) { view.setScrollY(scrollY); } }
static void setScrollY(View view, int scrollY) { view.setScrollY(scrollY); }
@Override public void setValue(View object, int value) { object.setScrollY(value); }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) static void setScrollY(View view, int scrollY) { view.setScrollY(scrollY); }
/** * 开始滚动前 */ @Override public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) { int scrollY = target.getScrollY(); child.setScrollY(scrollY); super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed); }
private void scale(AppBarLayout abl, View target, int dy) { mTotalDy += -dy; mTotalDy = Math.min(mTotalDy, TARGET_HEIGHT); Log.e(TAG, "scale: mTotalDy==" + mTotalDy); mLastScale = Math.max(1f, 1f + mTotalDy / TARGET_HEIGHT); mTargetView.setScaleX(mLastScale); mTargetView.setScaleY(mLastScale); mLastBottom = mParentHeight + (int) (mTargetViewHeight / 2 * (mLastScale - 1)); // abl.setBottom(mLastBottom); target.setScrollY(0); // // middleLayout.setTop(mLastBottom - mMiddleHeight); // middleLayout.setBottom(mLastBottom); if (onProgressChangeListener != null) { float progress = Math.min((mLastScale - 1) / MAX_REFRESH_LIMIT, 1);//计算0~1的进度 onProgressChangeListener.onProgressChange(progress, false); } }
public void backToTop(){ View dependentView = getDependentView(); float translationY = dependentView.getTranslationY(); if (status == PAGE_TWO) { if (mode == 0) { childView.get().setScrollY(0); dependentView.setScrollY(0); scroller.startScroll(0, (int) translationY, 0, (int) (-translationY)); status = PAGE_ONE; if (mOnPageChanged!=null){ mOnPageChanged.toTop(); } } } handler.post(new Running()); }
public void scrollToBottom(){ View dependentView = getDependentView(); float translationY = dependentView.getTranslationY(); dependentView.setScrollY(dependentView.getMeasuredHeight()); if (status == PAGE_ONE) { if (mode == 0) { scroller.startScroll(0, (int) translationY, 0, (int) (-dependentView.getMeasuredHeight() - translationY)); status = PAGE_TWO; if (mOnPageChanged!=null){ mOnPageChanged.toBottom(); } } } handler.post(new Running()); }
@Override public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target) { int height = dependentView.get().getHeight(); float translationY = childeView.get().getTranslationY(); if (translationY > height) { isExpand = true; } else { isExpand = false; } if (isExpand) { float pro = ((translationY - height) * 1.0f / heardSize); creatExpendAnimator(translationY, height, (int) (500 * pro)); } if (!isScroll && height > minHeard && height < heardSize) { childeView.get().setScrollY(0); if (height < 0.7 * heardSize) {//上滑 float pro = (height - minHeard) * 1.0f / (heardSize - minHeard); creatAnimation(height, minHeard, (int) (500 * pro)); } else {//下滑 float pro = (heardSize - height) * 1.0f / (heardSize - minHeard); creatAnimation(height, heardSize, (int) (500 * pro)); } isScroll = true; } }
private void scale(AppBarLayout abl, View target, int dy) { mTotalDy += -dy; mTotalDy = Math.min(mTotalDy, TARGET_HEIGHT); mLastScale = Math.max(1f, 1f + mTotalDy / TARGET_HEIGHT); ViewCompat.setScaleX(mTargetView, mLastScale); ViewCompat.setScaleY(mTargetView, mLastScale); mLastBottom = mParentHeight + (int) (mTargetViewHeight / 2 * (mLastScale - 1)); abl.setBottom(mLastBottom); target.setScrollY(0); middleLayout.setTop(mLastBottom - mMiddleHeight); middleLayout.setBottom(mLastBottom); if (onProgressChangeListener != null) { float progress = Math.min((mLastScale - 1) / MAX_REFRESH_LIMIT, 1);//计算0~1的进度 onProgressChangeListener.onProgressChange(progress, false); } }