/** Override method to configure the dragged view and secondView layout properly. */ @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { if (isInEditMode()) super.onLayout(changed, left, top, right, bottom); else if (isDragViewAtTop()) { dragView.layout(left, top, right, transformer.getOriginalHeight()); secondView.layout(left, transformer.getOriginalHeight(), right, bottom); ViewHelper.setY(dragView, top); ViewHelper.setY(secondView, transformer.getOriginalHeight()); } else { secondView.layout(left, transformer.getOriginalHeight(), right, bottom); } }
void setDegree(float degree) { mValue = degree; View clipView = mTarget.get(); float x = mArcMetric.getAxisPoint().x + mArcMetric.mRadius * Utils.cos(degree); float y = mArcMetric.getAxisPoint().y - mArcMetric.mRadius * Utils.sin(degree); ViewHelper.setX(clipView, x - clipView.getWidth() / 2); ViewHelper.setY(clipView, y - clipView.getHeight() / 2); }
/** At this time, we can get view size in dialog(可以获得对话框内视图大小) */ @Override public void onLayoutObtain() { int x = mX; int y = mY; if (mGravity == Gravity.TOP) { y = mY - mLlContent.getHeight(); } if (mAlignCenter) { x = mX + mAnchorView.getWidth() / 2 - mLlContent.getWidth() / 2; } x = getX(x); y = getY(y); x = getX(x + dp2px(mXOffset)); y = getY(y + dp2px(mYOffset)); ViewHelper.setX(mLlContent, x); ViewHelper.setY(mLlContent, y); }
@Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { // 首次使用获取banner初始高度和宽度 if (originHeight == -1 || originWidth == -1) { originHeight = mTopView.getHeight(); originWidth = mTopView.getWidth(); } // t为ScrollView向上滑动的量, 两者相减即为当前banner所需的高度 int height = originHeight - t; // 计算缩放比例 float newRatio = (float) height / (float) originHeight; // 修改banner的属性 if (height >= 0) { ViewHelper.setScaleX(mTopView, newRatio); ViewHelper.setScaleY(mTopView, newRatio); ViewHelper.setY(mTopView, t / 2); ViewHelper.setAlpha(mTopView, newRatio); } super.onScrollChanged(l, t, oldl, oldt); }
public void setY(float y) { ViewHelper.setY(this, y); }
/** Modify secondView position to be always below dragged view. */ void changeSecondViewPosition() { ViewHelper.setY(secondView, dragView.getBottom()); }
/** * Called when a scroller(RecyclerView/ListView,ScrollView,WebView) scrolled by the user * * @param source the scroller * @param yOffset the scroller current yOffset */ public boolean onMaterialScrolled(Object source, float yOffset) { if (initialDistance == -1 || initialDistance == 0) { initialDistance = mHeader.mPagerSlidingTabStrip.getTop() - mHeader.toolbar.getBottom(); } // only if yOffset changed if (yOffset == lastYOffset) return false; float scrollTop = -yOffset; { // parallax scroll of the Background ImageView (the KenBurnsView) if (mHeader.headerBackground != null) { if (this.settings.parallaxHeaderFactor != 0) ViewHelper.setTranslationY( mHeader.headerBackground, scrollTop / this.settings.parallaxHeaderFactor); if (ViewHelper.getY(mHeader.headerBackground) >= 0) ViewHelper.setY(mHeader.headerBackground, 0); } } if (ENABLE_LOG) Log.d("yOffset", "" + yOffset); // dispatch the new offset to all registered scrollables dispatchScrollOffset(source, minMax(0, yOffset, scrollMaxDp)); float percent = yOffset / scrollMax; if (ENABLE_LOG) Log.d("percent1", "" + percent); if (percent != 0) { // distance between pager & toolbar float newDistance = ViewHelper.getY(mHeader.mPagerSlidingTabStrip) - mHeader.toolbar.getBottom(); percent = 1 - newDistance / initialDistance; if (ENABLE_LOG) Log.d("percent2", "" + percent); } if (Float.isNaN(percent)) // fix for orientation change return false; // fix quick scroll if (percent == 0 && headerAnimator != null) { cancelHeaderAnimator(); ViewHelper.setTranslationY(mHeader.toolbarLayout, 0); } percent = minMax(0, percent, 1); { if (!settings.toolbarTransparent) { // change color of toolbar & viewpager indicator & statusBaground setColorPercent(percent); } else { if (justToolbarAnimated) { if (toolbarJoinsTabs()) setColorPercent(1); else if (lastPercent != percent) { animateColorPercent(0, 200); } } } lastPercent = percent; // save the percent if (mHeader.mPagerSlidingTabStrip != null) { // move the viewpager indicator // float newY = ViewHelper.getY(mHeader.mPagerSlidingTabStrip) + scrollTop; if (ENABLE_LOG) Log.d(TAG, "" + scrollTop); // mHeader.mPagerSlidingTabStrip.setTranslationY(mHeader.getToolbar().getBottom()-mHeader.mPagerSlidingTabStrip.getY()); if (scrollTop <= 0) { ViewHelper.setTranslationY(mHeader.mPagerSlidingTabStrip, scrollTop); ViewHelper.setTranslationY(mHeader.toolbarLayoutBackground, scrollTop); // when if (ViewHelper.getY(mHeader.mPagerSlidingTabStrip) < mHeader.getToolbar().getBottom()) { float ty = mHeader.getToolbar().getBottom() - mHeader.mPagerSlidingTabStrip.getTop(); ViewHelper.setTranslationY(mHeader.mPagerSlidingTabStrip, ty); ViewHelper.setTranslationY(mHeader.toolbarLayoutBackground, ty); } } } if (mHeader.mLogo != null) { // move the header logo to toolbar if (this.settings.hideLogoWithFade) { ViewHelper.setAlpha(mHeader.mLogo, 1 - percent); ViewHelper.setTranslationY( mHeader.mLogo, (mHeader.finalTitleY - mHeader.originalTitleY) * percent); } else { ViewHelper.setTranslationY( mHeader.mLogo, (mHeader.finalTitleY - mHeader.originalTitleY) * percent); ViewHelper.setTranslationX( mHeader.mLogo, (mHeader.finalTitleX - mHeader.originalTitleX) * percent); float scale = (1 - percent) * (1 - mHeader.finalScale) + mHeader.finalScale; setScale(scale, mHeader.mLogo); } } if (this.settings.hideToolbarAndTitle && mHeader.toolbarLayout != null) { boolean scrollUp = lastYOffset < yOffset; if (scrollUp) { scrollUp(yOffset); } else { scrollDown(yOffset); } } } if (headerAnimator != null && percent < 1) { cancelHeaderAnimator(); } lastYOffset = yOffset; return true; }