Java Code Examples for android.view.View#getTranslationY()

The following examples show how to use android.view.View#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: StickyHeadersLinearLayoutManager.java    From RecyclerViewExtensions with MIT License 6 votes vote down vote up
/**
 * Returns true when the {@code view} is at the edge of the parent {@link RecyclerView}.
 */
private boolean isViewOnBoundary(View view) {
    if (getOrientation() == VERTICAL) {
        if (getReverseLayout()) {
            return view.getBottom() - view.getTranslationY() > getHeight() + mTranslationY;
        } else {
            return view.getTop() + view.getTranslationY() < mTranslationY;
        }
    } else {
        if (getReverseLayout()) {
            return view.getRight() - view.getTranslationX() > getWidth() + mTranslationX;
        } else {
            return view.getLeft() + view.getTranslationX() < mTranslationX;
        }
    }
}
 
Example 2
Source File: GroupHeaderBehavior.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
@Override
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
    logD(TAG, "onNestedScroll: dyConsumed=" + dyConsumed + "  dyUnconsumed= " + dyUnconsumed);

    if (dyUnconsumed > 0) {
        return;
    }

    float translationY = child.getTranslationY() - dyUnconsumed;
    int maxHeadTranslateY = 0;
    if (translationY > maxHeadTranslateY) {
        translationY = maxHeadTranslateY;
    }

    logD(TAG, "onNestedScroll: translationY=" + translationY);

    if (child.getTranslationY() != translationY) {
        onScrollChange(type, (int) translationY);
        child.setTranslationY(translationY);
    }


}
 
Example 3
Source File: MainHeaderBehavior.java    From BehaviorDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 是否可以整体滑动
 *
 * @return
 */
private boolean canScroll(View child, float scrollY) {
    if (scrollY > 0 && child.getTranslationY() > getHeaderOffset()) {
        return true;
    }

    if (child.getTranslationY() == getHeaderOffset() && upReach) {
        return true;
    }

    if (scrollY < 0 && !downReach) {
        return true;
    }

    return false;
}
 
Example 4
Source File: TranslationAnimationCreator.java    From scene with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an animator that can be used for x and/or y translations. When interrupted,
 * it sets a tag to keep track of the position so that it may be continued from position.
 *
 * @param view         The view being moved. This may be in the overlay for onDisappear.
 * @param values       The values containing the view in the view hierarchy.
 * @param viewPosX     The x screen coordinate of view
 * @param viewPosY     The y screen coordinate of view
 * @param startX       The start translation x of view
 * @param startY       The start translation y of view
 * @param endX         The end translation x of view
 * @param endY         The end translation y of view
 * @param interpolator The interpolator to use with this animator.
 * @return An animator that moves from (startX, startY) to (endX, endY) unless there was
 * a previous interruption, in which case it moves from the current position to (endX, endY).
 */
static PathInteractionAnimation createAnimation(View view, int viewPosX, int viewPosY,
                                                float startX, float startY, float endX, float endY, TimeInterpolator interpolator) {
    float terminalX = view.getTranslationX();
    float terminalY = view.getTranslationY();

    // Initial position is at translation startX, startY, so position is offset by that amount
    int startPosX = viewPosX + Math.round(startX - terminalX);
    int startPosY = viewPosY + Math.round(startY - terminalY);

    view.setTranslationX(startX);
    view.setTranslationY(startY);
    if (startX == endX && startY == endY) {
        return null;
    }
    Path path = new Path();
    path.moveTo(startX, startY);
    path.lineTo(endX, endY);

    return new PathInteractionAnimation(1.0f, path, view);
}
 
Example 5
Source File: SearchBehavior.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
    int headerOffsetRange = getHeaderOffsetRange();
    int titleOffsetRange = getSearchOffest();
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "offsetChildAsNeeded:" + dependency.getTranslationY());
    }
    if (dependency.getTranslationY() == headerOffsetRange) {
        child.setTranslationY(titleOffsetRange);
    } else if (dependency.getTranslationY() == 0) {
        child.setTranslationY(0);
    } else {
        child.setTranslationY((int) (dependency.getTranslationY() / (headerOffsetRange * 1.0f) * titleOffsetRange));
    }

}
 
Example 6
Source File: CellLayout.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
public ReorderPreviewAnimation(View child, int mode, int cellX0, int cellY0, int cellX1,
        int cellY1, int spanX, int spanY) {
    regionToCenterPoint(cellX0, cellY0, spanX, spanY, mTmpPoint);
    final int x0 = mTmpPoint[0];
    final int y0 = mTmpPoint[1];
    regionToCenterPoint(cellX1, cellY1, spanX, spanY, mTmpPoint);
    final int x1 = mTmpPoint[0];
    final int y1 = mTmpPoint[1];
    final int dX = x1 - x0;
    final int dY = y1 - y0;
    finalDeltaX = 0;
    finalDeltaY = 0;
    int dir = mode == MODE_HINT ? -1 : 1;
    if (dX == dY && dX == 0) {
    } else {
        if (dY == 0) {
            finalDeltaX = - dir * Math.signum(dX) * mReorderPreviewAnimationMagnitude;
        } else if (dX == 0) {
            finalDeltaY = - dir * Math.signum(dY) * mReorderPreviewAnimationMagnitude;
        } else {
            double angle = Math.atan( (float) (dY) / dX);
            finalDeltaX = (int) (- dir * Math.signum(dX) *
                    Math.abs(Math.cos(angle) * mReorderPreviewAnimationMagnitude));
            finalDeltaY = (int) (- dir * Math.signum(dY) *
                    Math.abs(Math.sin(angle) * mReorderPreviewAnimationMagnitude));
        }
    }
    this.mode = mode;
    initDeltaX = child.getTranslationX();
    initDeltaY = child.getTranslationY();
    finalScale = getChildrenScale() - 4.0f / child.getWidth();
    initScale = child.getScaleX();
    this.child = child;
}
 
Example 7
Source File: ViewPropertyAnimatorHC.java    From Mover with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets the value of the named property from the View object.
 *
 * @param propertyConstant The property whose value should be returned
 * @return float The value of the named property
 */
private float getValue(int propertyConstant) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //return info.mTranslationX;
                return v.getTranslationX();
            case TRANSLATION_Y:
                //return info.mTranslationY;
                return v.getTranslationY();
            case ROTATION:
                //return info.mRotation;
                return v.getRotation();
            case ROTATION_X:
                //return info.mRotationX;
                return v.getRotationX();
            case ROTATION_Y:
                //return info.mRotationY;
                return v.getRotationY();
            case SCALE_X:
                //return info.mScaleX;
                return v.getScaleX();
            case SCALE_Y:
                //return info.mScaleY;
                return v.getScaleY();
            case X:
                //return v.mLeft + info.mTranslationX;
                return v.getX();
            case Y:
                //return v.mTop + info.mTranslationY;
                return v.getY();
            case ALPHA:
                //return info.mAlpha;
                return v.getAlpha();
        }
    }
    return 0;
}
 
Example 8
Source File: ViewHelper.java    From SwipeBack with Apache License 2.0 5 votes vote down vote up
public static int getTop(View v) {
    if (SwipeBack.USE_TRANSLATIONS) {
        return (int) (v.getTop() + v.getTranslationY());
    }

    return v.getTop();
}
 
Example 9
Source File: UDView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取TranslationY
 *
 * @return
 */
public float getTranslationY() {
    View view = getView();
    if (view != null) {
        return view.getTranslationY();
    }
    return 0;
}
 
Example 10
Source File: DoubleHeaderDecoration.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
private int getAnimatedTop(View child) {
    return child.getTop() + (int)child.getTranslationY();
}
 
Example 11
Source File: Animer.java    From Animer with Apache License 2.0 4 votes vote down vote up
@Override
public float getValue(View view) {
    return view.getTranslationY();
}
 
Example 12
Source File: ViewHelper.java    From timecat with Apache License 2.0 4 votes vote down vote up
static float getTranslationY(View view) {
    return view.getTranslationY();
}
 
Example 13
Source File: Slide.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
@Override
public float getGone(float distance, View view) {
    return view.getTranslationY() - distance;
}
 
Example 14
Source File: TVDetails.java    From moviedb-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    float scroll = scrollY;
    if (mViewPager.getCurrentItem() == 0) {
        scroll = (scroll / scrollSpeed);

        if (scrollY / scale >= 0 && onMoreIconClick.getKey())
            onMoreIconClick.onClick(null);
    }

    if (dragging) {
        View toolbarView = getActivity().findViewById(R.id.toolbar);

        if (scroll > oldScrollY) {

            if (upDyKey) {
                upDy = scroll;
                upDyKey = false;
            } else {
                dy = upDy - scroll;

                if (dy >= -toolbarView.getHeight()) {
                    toolbarView.setTranslationY(dy);
                    mSlidingTabLayout.setTranslationY(dy);
                } else {
                    toolbarView.setTranslationY(-toolbarView.getHeight());
                    mSlidingTabLayout.setTranslationY(-toolbarView.getHeight());
                }

                downDyKey = true;
            }

        }

        if (scroll < oldScrollY) {

            if (downDyKey) {
                downDy = scroll;
                downDyTrans = toolbarView.getTranslationY();
                downDyKey = false;
            } else {

                dy = (downDyTrans + (downDy - scroll));
                if (dy <= 0) {
                    toolbarView.setTranslationY(dy);
                    mSlidingTabLayout.setTranslationY(dy);
                } else {
                    toolbarView.setTranslationY(0);
                    mSlidingTabLayout.setTranslationY(0);
                }

                upDyKey = true;

            }
        }


    }

    oldScrollY = scroll;
}
 
Example 15
Source File: ViewHelper.java    From KJFrameForAndroid with Apache License 2.0 4 votes vote down vote up
static float getTranslationY(View view) {
    return view.getTranslationY();
}
 
Example 16
Source File: XiamiTitleBehavior.java    From BehaviorDemo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    float y = -(1 - dependency.getTranslationY() / getHeaderOffset()) * getTitleHeight();
    child.setY(y);
    return true;
}
 
Example 17
Source File: ViewCompatHC.java    From letv with Apache License 2.0 4 votes vote down vote up
public static float getTranslationY(View view) {
    return view.getTranslationY();
}
 
Example 18
Source File: ViewHelper.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
static float getTranslationY(View view) {
    return view.getTranslationY();
}
 
Example 19
Source File: Slide.java    From scene with Apache License 2.0 4 votes vote down vote up
@Override
public float getGoneY(ViewGroup sceneRoot, View view, float fraction) {
    return view.getTranslationY() + sceneRoot.getHeight() * fraction;
}
 
Example 20
Source File: Slide.java    From scene with Apache License 2.0 4 votes vote down vote up
@Override
public float getGoneY(ViewGroup sceneRoot, View view, float fraction) {
    return view.getTranslationY();
}