Java Code Examples for androidx.core.view.ViewCompat#getTranslationY()
The following examples show how to use
androidx.core.view.ViewCompat#getTranslationY() .
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
Source File: VerticalDividerItemDecoration.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
@Override protected Rect getDividerBound(int position, RecyclerView parent, View child) { Rect bounds = new Rect(0, 0, 0, 0); int transitionX = (int) ViewCompat.getTranslationX(child); int transitionY = (int) ViewCompat.getTranslationY(child); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); bounds.top = parent.getPaddingTop() + mMarginProvider.dividerTopMargin(position, parent) + transitionY; bounds.bottom = parent.getHeight() - parent.getPaddingBottom() - mMarginProvider.dividerBottomMargin(position, parent) + transitionY; int dividerSize = getDividerSize(position, parent); if (mDividerType == DividerType.DRAWABLE) { bounds.left = child.getRight() + params.leftMargin + transitionX; bounds.right = bounds.left + dividerSize; } else { bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX; bounds.right = bounds.left; } return bounds; }
Example 2
Source File: DoubleHeaderDecoration.java From header-decor with Apache License 2.0 | 6 votes |
@Nullable public View findSubHeaderViewUnder(float x, float y) { for (RecyclerView.ViewHolder holder : subHeaderCache.values()) { final View child = holder.itemView; final float translationX = ViewCompat.getTranslationX(child); final float translationY = ViewCompat.getTranslationY(child); if (x >= child.getLeft() + translationX && x <= child.getRight() + translationX && y >= child.getTop() + translationY && y <= child.getBottom() + translationY) { return child; } } return null; }
Example 3
Source File: DoubleHeaderDecoration.java From header-decor with Apache License 2.0 | 6 votes |
@Nullable public View findHeaderViewUnder(float x, float y) { for (RecyclerView.ViewHolder holder : headerCache.values()) { final View child = holder.itemView; final float translationX = ViewCompat.getTranslationX(child); final float translationY = ViewCompat.getTranslationY(child); if (x >= child.getLeft() + translationX && x <= child.getRight() + translationX && y >= child.getTop() + translationY && y <= child.getBottom() + translationY) { return child; } } return null; }
Example 4
Source File: StickyHeaderDecoration.java From header-decor with Apache License 2.0 | 6 votes |
@Nullable public View findHeaderViewUnder(float x, float y) { for (RecyclerView.ViewHolder holder : headerCache.values()) { final View child = holder.itemView; final float translationX = ViewCompat.getTranslationX(child); final float translationY = ViewCompat.getTranslationY(child); if (x >= child.getLeft() + translationX && x <= child.getRight() + translationX && y >= child.getTop() + translationY && y <= child.getBottom() + translationY) { return child; } } return null; }
Example 5
Source File: ViewPagerTabFragmentParentFragment.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
private void animateToolbar(final float toY) { float layoutTranslationY = ViewCompat.getTranslationY(mInterceptionLayout); if (layoutTranslationY != toY) { ValueAnimator animator = ValueAnimator.ofFloat(ViewCompat.getTranslationY(mInterceptionLayout), toY).setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float translationY = (float) animation.getAnimatedValue(); View tView = adjustmentToolBarView(); ViewCompat.setTranslationY(mInterceptionLayout, translationY); ViewCompat.setTranslationY(tView, translationY); if (translationY < 0) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); lp.height = (int) (-translationY + getScreenHeight()); mInterceptionLayout.requestLayout(); } } }); animator.start(); } }
Example 6
Source File: ViewPagerTabFragmentParentFragment.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (dragging) { int headerBannerHeight = headerBanner.getHeight(); float currentHeaderTranslationY = ViewCompat.getTranslationY(mHeaderContainer); if (firstScroll) { if (-headerBannerHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } final float headerTranslationY = ScrollUtils.getFloat(mBaseTranslationY - scrollY, -headerBannerHeight, 0); ViewCompat.animate(mHeaderContainer).cancel(); ViewCompat.setTranslationY(mHeaderContainer, headerTranslationY); //todo: need some more works on this setpagertoppadding(totalfullheight - headerTranslationY); } }
Example 7
Source File: HorizontalDividerItemDecoration.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
@Override protected Rect getDividerBound(int position, RecyclerView parent, View child) { Rect bounds = new Rect(0, 0, 0, 0); int transitionX = (int) ViewCompat.getTranslationX(child); int transitionY = (int) ViewCompat.getTranslationY(child); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); bounds.left = parent.getPaddingLeft() + mMarginProvider.dividerLeftMargin(position, parent) + transitionX; bounds.right = parent.getWidth() - parent.getPaddingRight() - mMarginProvider.dividerRightMargin(position, parent) + transitionX; int dividerSize = getDividerSize(position, parent); if (mDividerType == DividerType.DRAWABLE) { bounds.top = child.getBottom() + params.topMargin + transitionY; bounds.bottom = bounds.top + dividerSize; } else { bounds.top = child.getBottom() + params.topMargin + dividerSize / 2 + transitionY; bounds.bottom = bounds.top; } return bounds; }
Example 8
Source File: UltimateRecyclerView.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void moveView(final View mView, final UltimateRecyclerView ultimateRecyclerView, final int screenheight, float toTranslationY) { if (ViewCompat.getTranslationY(mView) == toTranslationY) { return; } ValueAnimator animator = ValueAnimator.ofFloat(ViewCompat.getTranslationY(mView), toTranslationY).setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float translationY = (float) animation.getAnimatedValue(); ViewCompat.setTranslationY(mView, translationY); ViewCompat.setTranslationY((View) ultimateRecyclerView, translationY); // FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) ((View) ultimateRecyclerView).getLayoutParams(); MarginLayoutParams layoutParams = (MarginLayoutParams) ((View) ultimateRecyclerView).getLayoutParams(); layoutParams.height = (int) -translationY + screenheight - layoutParams.topMargin; ((View) ultimateRecyclerView).requestLayout(); } }); animator.start(); }
Example 9
Source File: UltimateRecyclerView.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void moveToolbar(final Toolbar mToolbar, final UltimateRecyclerView ultimateRecyclerView, final int screenheight, float toTranslationY) { if (ViewCompat.getTranslationY(mToolbar) == toTranslationY) { return; } ValueAnimator animator = ValueAnimator.ofFloat(ViewCompat.getTranslationY(mToolbar), toTranslationY).setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float translationY = (float) animation.getAnimatedValue(); ViewCompat.setTranslationY(mToolbar, translationY); ViewCompat.setTranslationY((View) ultimateRecyclerView, translationY); // FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) ((View) ultimateRecyclerView).getLayoutParams(); MarginLayoutParams layoutParams = (MarginLayoutParams) ((View) ultimateRecyclerView).getLayoutParams(); layoutParams.height = (int) -translationY + screenheight - layoutParams.topMargin; ((View) ultimateRecyclerView).requestLayout(); } }); animator.start(); }
Example 10
Source File: BaseItemAnimator.java From recyclerview-animators with Apache License 2.0 | 6 votes |
@Override public boolean animateMove(final ViewHolder holder, int fromX, int fromY, int toX, int toY) { final View view = holder.itemView; fromX += ViewCompat.getTranslationX(holder.itemView); fromY += ViewCompat.getTranslationY(holder.itemView); endAnimation(holder); int deltaX = toX - fromX; int deltaY = toY - fromY; if (deltaX == 0 && deltaY == 0) { dispatchMoveFinished(holder); return false; } if (deltaX != 0) { ViewCompat.setTranslationX(view, -deltaX); } if (deltaY != 0) { ViewCompat.setTranslationY(view, -deltaY); } mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY)); return true; }
Example 11
Source File: BaseItemAnimator.java From recyclerview-animators with Apache License 2.0 | 5 votes |
@Override public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { if (oldHolder == newHolder) { // Don't know how to run change animations when the same view holder is re-used. // run a move animation to handle position changes. return animateMove(oldHolder, fromX, fromY, toX, toY); } final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView); final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView); final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView); endAnimation(oldHolder); int deltaX = (int) (toX - fromX - prevTranslationX); int deltaY = (int) (toY - fromY - prevTranslationY); // recover prev translation state after ending animation ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX); ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY); ViewCompat.setAlpha(oldHolder.itemView, prevAlpha); if (newHolder != null && newHolder.itemView != null) { // carry over translation values endAnimation(newHolder); ViewCompat.setTranslationX(newHolder.itemView, -deltaX); ViewCompat.setTranslationY(newHolder.itemView, -deltaY); ViewCompat.setAlpha(newHolder.itemView, 0); } mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY)); return true; }
Example 12
Source File: ViewPagerTabFragmentParentFragment.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
@Override public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) { if (!mScrolled && mSlop < Math.abs(diffX) && Math.abs(diffY) < Math.abs(diffX)) { // Horizontal scroll is maybe handled by ViewPager return false; } Scrollable scrollable = getCurrentScrollable(); if (scrollable == null) { mScrolled = false; return false; } // If interceptionLayout can move, it should intercept. // And once it begins to move, horizontal scroll shouldn't work any longer. // View toolbarView = getActivity().findViewById(R.id.toolbar); int headerBannerHeight = headerBanner.getHeight(); int translationY = (int) ViewCompat.getTranslationY(mInterceptionLayout); boolean scrollingUp = 0 < diffY; boolean scrollingDown = diffY < 0; if (scrollingUp) { if (translationY < 0) { mScrolled = true; mLastScrollState = ObservableScrollState.UP; return true; } } else if (scrollingDown) { if (-headerBannerHeight < translationY) { mScrolled = true; mLastScrollState = ObservableScrollState.DOWN; return true; } } mScrolled = false; return false; }
Example 13
Source File: ViewPagerTabFragmentParentFragment.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
private boolean toolbarIsHidden() { View view = getView(); if (view == null) { return false; } View tView = adjustmentToolBarView(); return ViewCompat.getTranslationY(mInterceptionLayout) == -tView.getHeight(); }
Example 14
Source File: ItemTouchHelperExtension.java From CrazyDaily with Apache License 2.0 | 5 votes |
private void getSelectedDxDy(float[] outPosition) { if ((mSelectedFlags & (LEFT | RIGHT)) != 0) { outPosition[0] = mSelectedStartX + mDx - mSelected.itemView.getLeft(); } else { outPosition[0] = ViewCompat.getTranslationX(mSelected.itemView); } if ((mSelectedFlags & (UP | DOWN)) != 0) { outPosition[1] = mSelectedStartY + mDy - mSelected.itemView.getTop(); } else { outPosition[1] = ViewCompat.getTranslationY(mSelected.itemView); } }
Example 15
Source File: HorizontalDividerItemDecoration.java From DoraemonKit with Apache License 2.0 | 5 votes |
@Override protected Rect getDividerBound(int position, RecyclerView parent, View child) { Rect bounds = new Rect(0, 0, 0, 0); int transitionX = (int) ViewCompat.getTranslationX(child); int transitionY = (int) ViewCompat.getTranslationY(child); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); bounds.left = child.getLeft() + transitionX; bounds.right = child.getRight() + transitionX; int dividerSize = getDividerSize(position, parent); if (mDividerType == DividerType.DRAWABLE || mDividerType == DividerType.SPACE) { if (alignLeftEdge(parent, position)) { bounds.left += mMarginProvider.dividerLeftMargin(position, parent); } if (alignRightEdge(parent, position)) { bounds.right -= mMarginProvider.dividerRightMargin(position, parent); } else { // 交叉位置特殊处理 bounds.right += getDividerSize(position, parent); } bounds.top = child.getBottom() + params.bottomMargin + transitionY; bounds.bottom = bounds.top + dividerSize; } else { int halfSize = dividerSize / 2; bounds.top = child.getBottom() + params.bottomMargin + halfSize + transitionY; bounds.bottom = bounds.top; } if (mPositionInsideItem) { bounds.top -= dividerSize; bounds.bottom -= dividerSize; } return bounds; }
Example 16
Source File: VerticalDividerItemDecoration.java From DoraemonKit with Apache License 2.0 | 5 votes |
@Override protected Rect getDividerBound(int position, RecyclerView parent, View child) { Rect bounds = new Rect(0, 0, 0, 0); int transitionX = (int) ViewCompat.getTranslationX(child); int transitionY = (int) ViewCompat.getTranslationY(child); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); bounds.top = child.getTop() + transitionY; bounds.bottom = child.getBottom() + transitionY; int dividerSize = getDividerSize(position, parent); if (mDividerType == DividerType.DRAWABLE || mDividerType == DividerType.SPACE) { if (alignTopEdge(parent, position)) { bounds.top += mMarginProvider.dividerTopMargin(position, parent); } if (alignBottomEdge(parent, position)) { bounds.bottom -= mMarginProvider.dividerBottomMargin(position, parent); } bounds.left = child.getRight() + params.rightMargin + transitionX; bounds.right = bounds.left + dividerSize; } else { // set center point of divider int halfSize = dividerSize / 2; bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX; bounds.right = bounds.left; } if (mPositionInsideItem) { bounds.left -= dividerSize; bounds.right -= dividerSize; } return bounds; }
Example 17
Source File: HorizontalDividerItemDecoration.java From DoraemonKit with Apache License 2.0 | 5 votes |
@Override protected Rect getDividerBound(int position, RecyclerView parent, View child) { Rect bounds = new Rect(0, 0, 0, 0); int transitionX = (int) ViewCompat.getTranslationX(child); int transitionY = (int) ViewCompat.getTranslationY(child); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); bounds.left = child.getLeft() + transitionX; bounds.right = child.getRight() + transitionX; int dividerSize = getDividerSize(position, parent); if (mDividerType == DividerType.DRAWABLE || mDividerType == DividerType.SPACE) { if (alignLeftEdge(parent, position)) { bounds.left += mMarginProvider.dividerLeftMargin(position, parent); } if (alignRightEdge(parent, position)) { bounds.right -= mMarginProvider.dividerRightMargin(position, parent); } else { // 交叉位置特殊处理 bounds.right += getDividerSize(position, parent); } bounds.top = child.getBottom() + params.bottomMargin + transitionY; bounds.bottom = bounds.top + dividerSize; } else { int halfSize = dividerSize / 2; bounds.top = child.getBottom() + params.bottomMargin + halfSize + transitionY; bounds.bottom = bounds.top; } if (mPositionInsideItem) { bounds.top -= dividerSize; bounds.bottom -= dividerSize; } return bounds; }
Example 18
Source File: UltimateRecyclerView.java From UltimateRecyclerView with Apache License 2.0 | 4 votes |
public boolean toolbarIsHidden(Toolbar mToolbar) { return ViewCompat.getTranslationY(mToolbar) == -mToolbar.getHeight(); }
Example 19
Source File: UltimateRecyclerView.java From UltimateRecyclerView with Apache License 2.0 | 4 votes |
public boolean toolbarIsShown(Toolbar mToolbar) { return ViewCompat.getTranslationY(mToolbar) == 0; }
Example 20
Source File: ViewPagerTabFragmentParentFragment.java From UltimateRecyclerView with Apache License 2.0 | 4 votes |
private boolean toolbarIsShown() { return ViewCompat.getTranslationY(mInterceptionLayout) == 0; }