Java Code Examples for android.support.v4.view.ViewCompat#getTranslationY()
The following examples show how to use
android.support.v4.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: DoubleHeaderDecoration.java From LRecyclerView with Apache License 2.0 | 6 votes |
public View findSubHeaderViewUnder(float x, float y) { for (RecyclerView.ViewHolder holder : mSubHeaderCache.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 2
Source File: BaseItemAnimator.java From GankGirl with GNU Lesser General Public License v2.1 | 6 votes |
@Override public boolean animateMove(final RecyclerView.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); resetAnimation(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 3
Source File: ScaleInItemAnimator.java From androidexamples with Apache License 2.0 | 6 votes |
@Override public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int 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 4
Source File: ReItemTouchHelper.java From ReSwipeCard with Apache License 2.0 | 5 votes |
private void getSelectedDxDy(float[] outPosition) { float dx = isManually ? 0 : mDx; float dy = isManually ? 0 : mDy; if ((mSelectedFlags & (LEFT | RIGHT)) != 0) { outPosition[0] = mSelectedStartX + dx - mSelected.itemView.getLeft(); } else { outPosition[0] = ViewCompat.getTranslationX(mSelected.itemView); } if ((mSelectedFlags & (UP | DOWN)) != 0) { outPosition[1] = mSelectedStartY + dy - mSelected.itemView.getTop(); } else { outPosition[1] = ViewCompat.getTranslationY(mSelected.itemView); } }
Example 5
Source File: MyTaskAdapter.java From Conquer with Apache License 2.0 | 5 votes |
@Override public boolean onCheckCanStartDrag(TaskViewHolder holder, int position, int x, int y) { // x, y --- relative from the itemView's top-left final View mContainerView = holder.mContainer; final View dragHandleView = holder.mDragHandle; final int offsetX = mContainerView.getLeft() + (int) (ViewCompat.getTranslationX(mContainerView) + 0.5f); final int offsetY = mContainerView.getTop() + (int) (ViewCompat.getTranslationY(mContainerView) + 0.5f); return hitTest(dragHandleView, x - offsetX, y - offsetY); }
Example 6
Source File: BottomNavigationBehavior.java From NanoIconPack with Apache License 2.0 | 5 votes |
private void updateScrollingForSnackbar(View dependency, V child, boolean enabled) { if (dependency instanceof Snackbar.SnackbarLayout) { scrollingEnabled = enabled; if (!hideAlongSnackbar && ViewCompat.getTranslationY(child) != 0) { ViewCompat.setTranslationY(child, 0); hidden = false; hideAlongSnackbar = true; } else if (hideAlongSnackbar) { hidden = true; animateOffset(child, -child.getHeight()); } } }
Example 7
Source File: StickyNormalItemLine.java From YCRefreshView with Apache License 2.0 | 5 votes |
public View findHeaderViewUnder(float x, float y) { for (RecyclerView.ViewHolder holder : mHeaderCache.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 8
Source File: StickyHeadersItemDecoration.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { final int childCount = parent.getChildCount(); final RecyclerView.LayoutManager lm = parent.getLayoutManager(); View header = headerViewHolder.itemView; Float lastY = null; for (int i = childCount - 1; i >= 0; i--) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams)child.getLayoutParams(); final int position = parent.getChildPosition(child); RecyclerView.ViewHolder holder = parent.getChildViewHolder(child); if (!lp.isItemRemoved()) { float translationY = ViewCompat.getTranslationY(child); if (i == 0 || isHeader(holder)) { float y = getHeaderY(child, lm) + translationY; if (lastY != null && lastY < y + headerHeight) { y = lastY - headerHeight; } adapter.onBindViewHolder(headerViewHolder, position); c.save(); c.translate(0, y); header.draw(c); c.restore(); lastY = y; } } } }
Example 9
Source File: SuggestionItemDecorator.java From FloatingSearchView with Apache License 2.0 | 5 votes |
@Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { int visibleCount = parent.getChildCount(); int count = state.getItemCount(); RecyclerView.Adapter adapter = parent.getAdapter(); int adapterCount = adapter != null ? adapter.getItemCount() : 0; for (int i = 0; i < visibleCount; i++) { View view = parent.getChildAt(i); int position = parent.getChildAdapterPosition(view); float translationX = ViewCompat.getTranslationX(view); float translationY = ViewCompat.getTranslationY(view); float alpha = ViewCompat.getAlpha(view); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams(); int shadows = LEFT|RIGHT; if(position == count - 1 && adapterCount != 0) shadows|=BOTTOM; drawable.setAlpha((int) (255*alpha)); drawable.setShadow(shadows); drawable.setBounds(0, 0, parent.getWidth(), view.getHeight()); int saved = canvas.save(); canvas.translate(parent.getPaddingLeft() + translationX, view.getTop() + params.topMargin + translationY); drawable.draw(canvas); canvas.restoreToCount(saved); } }
Example 10
Source File: BaseItemAnimator.java From FloatingSearchView 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); resetAnimation(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) { // carry over translation values resetAnimation(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 11
Source File: MyDefaultItemAnimator.java From Dota2Helper with Apache License 2.0 | 5 votes |
@Override public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.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); resetAnimation(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) { // carry over translation values resetAnimation(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: BaseItemAnimator.java From onboarding-examples-android 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); resetAnimation(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) { // carry over translation values resetAnimation(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 13
Source File: VerticalDividerItemDecoration.java From AFBaseLibrary 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 = 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) { // set left and right position of divider if (mPositionInsideItem) { bounds.right = child.getRight() + params.leftMargin + transitionX; bounds.left = bounds.right - dividerSize; } else { bounds.left = child.getRight() + params.leftMargin + transitionX; bounds.right = bounds.left + dividerSize; } } else { // set center point of divider if (mPositionInsideItem) { bounds.left = child.getRight() + params.leftMargin - dividerSize / 2 + transitionX; } else { bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX; } bounds.right = bounds.left; } return bounds; }
Example 14
Source File: BaseItemAnimator.java From GankGirl with GNU Lesser General Public License v2.1 | 5 votes |
@Override public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.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); resetAnimation(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) { // carry over translation values resetAnimation(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 15
Source File: SheetBehavior.java From AndroidSweetBehavior with Apache License 2.0 | 4 votes |
private static void tickleInvalidationFlag(View view) { final float y = ViewCompat.getTranslationY(view); ViewCompat.setTranslationY(view, y + 1); ViewCompat.setTranslationY(view, y); }
Example 16
Source File: VerticalItemAnimator.java From JumpGo with Mozilla Public License 2.0 | 4 votes |
@Override public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { // if (oldHolder != newHolder) { // if (oldHolder != null) { // dispatchChangeFinished(oldHolder, true); // } // if (newHolder != null) { // dispatchChangeFinished(newHolder, false); // } // } else if (oldHolder != null) { // dispatchChangeFinished(oldHolder, true); // } // return false; 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. if ((fromX - toX) == 0 && (fromY - toY) == 0) { dispatchMoveFinished(oldHolder); return false; } 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); resetAnimation(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) { // carry over translation values resetAnimation(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 17
Source File: VerticalDividerItemDecoration.java From RecyclerView-FlexibleDivider with Apache License 2.0 | 4 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); boolean isReverseLayout = isReverseLayout(parent); if (mDividerType == DividerType.DRAWABLE) { // set left and right position of divider if (isReverseLayout) { bounds.right = child.getLeft() - params.leftMargin + transitionX; bounds.left = bounds.right - dividerSize; } else { bounds.left = child.getRight() + params.rightMargin + transitionX; bounds.right = bounds.left + dividerSize; } } else { // set center point of divider int halfSize = dividerSize / 2; if (isReverseLayout) { bounds.left = child.getLeft() - params.leftMargin - halfSize + transitionX; } else { bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX; } bounds.right = bounds.left; } if (mPositionInsideItem) { if (isReverseLayout) { bounds.left += dividerSize; bounds.right += dividerSize; } else { bounds.left -= dividerSize; bounds.right -= dividerSize; } } return bounds; }
Example 18
Source File: WeiboHeaderPagerBehavior.java From CoordinatorLayoutExample with Apache License 2.0 | 4 votes |
public void scrollToOpen(int duration) { float curTranslationY = ViewCompat.getTranslationY(mLayout); mOverScroller.startScroll(0, (int) curTranslationY, 0, (int) -curTranslationY, duration); start(); }
Example 19
Source File: HorizontalDividerItemDecoration.java From RecyclerView-FlexibleDivider with Apache License 2.0 | 4 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); boolean isReverseLayout = isReverseLayout(parent); if (mDividerType == DividerType.DRAWABLE) { // set top and bottom position of divider if (isReverseLayout) { bounds.bottom = child.getTop() - params.topMargin + transitionY; bounds.top = bounds.bottom - dividerSize; } else { bounds.top = child.getBottom() + params.bottomMargin + transitionY; bounds.bottom = bounds.top + dividerSize; } } else { // set center point of divider int halfSize = dividerSize / 2; if (isReverseLayout) { bounds.top = child.getTop() - params.topMargin - halfSize + transitionY; } else { bounds.top = child.getBottom() + params.bottomMargin + halfSize + transitionY; } bounds.bottom = bounds.top; } if (mPositionInsideItem) { if (isReverseLayout) { bounds.top += dividerSize; bounds.bottom += dividerSize; } else { bounds.top -= dividerSize; bounds.bottom -= dividerSize; } } return bounds; }
Example 20
Source File: ViewOffsetHelper.java From CoordinatorLayoutExample with Apache License 2.0 | 4 votes |
private static void tickleInvalidationFlag(View view) { final float y = ViewCompat.getTranslationY(view); ViewCompat.setTranslationY(view, y + 1); ViewCompat.setTranslationY(view, y); }