android.view.ViewPropertyAnimator#x ( )源码实例Demo

下面列出了android.view.ViewPropertyAnimator#x ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Animates a tab to be swiped horizontally.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, which should be swiped, as an instance of
 *         the class {@link TabItem}. The tab item may not be null
 * @param targetPosition
 *         The position on the x-axis, the tab should be moved to, in pixels as a {@link Float}
 *         value
 * @param selected
 *         True, if the tab should become the selected one, false otherwise
 * @param animationDuration
 *         The duration of the animation in milliseconds as a {@link Long} value
 * @param velocity
 *         The velocity of the drag gesture, which caused the tab to be swiped, in pixels per
 *         second as a {@link Float} value
 */
private void animateSwipe(@NonNull final TabItem tabItem, final float targetPosition,
                          final boolean selected, final long animationDuration,
                          final float velocity) {
    View view = contentViewRecycler.getView(tabItem.getTab());

    if (view != null) {
        float currentPosition = view.getX();
        float distance = Math.abs(targetPosition - currentPosition);
        float maxDistance = getTabSwitcher().getWidth() + swipedTabDistance;
        long duration = velocity > 0 ? Math.round((distance / velocity) * 1000) :
                Math.round(animationDuration * (distance / maxDistance));
        ViewPropertyAnimator animation = view.animate();
        animation.setListener(new AnimationListenerWrapper(
                selected ? createSwipeSelectedTabAnimationListener(tabItem) :
                        createSwipeNeighborAnimationListener(tabItem)));
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.setDuration(duration);
        animation.setStartDelay(0);
        animation.x(targetPosition);
        animation.start();
    }
}
 
源代码2 项目: Hentoid   文件: ZoomableRecyclerView.java
boolean zoomFling(int velocityX, int velocityY) {
    if (scale <= DEFAULT_SCALE) return false;

    float distanceTimeFactor = 0.4f;
    Float newX = null;
    Float newY = null;

    if (velocityX != 0 && canMoveHorizontally()) {
        float dx = (distanceTimeFactor * velocityX / 2);
        newX = getPositionX(getX() + dx);
    }
    if (velocityY != 0 && canMoveVertically()) {
        float dy = (distanceTimeFactor * velocityY / 2);
        newY = getPositionY(getY() + dy);
    }

    ViewPropertyAnimator animation = animate();
    if (newX != null) animation.x(newX);
    if (newY != null) animation.y(newY);
    animation.setInterpolator(new DecelerateInterpolator())
            .setDuration(400)
            .start();

    return true;
}
 
源代码3 项目: ChromeLikeTabSwitcher   文件: PhoneArithmetics.java
@Override
public final void animatePosition(@NonNull final Axis axis,
                                  @NonNull final ViewPropertyAnimator animator,
                                  @NonNull final AbstractItem item, final float position,
                                  final boolean includePadding) {
    Condition.INSTANCE.ensureNotNull(axis, "The axis may not be null");
    Condition.INSTANCE.ensureNotNull(animator, "The animator may not be null");
    Condition.INSTANCE.ensureNotNull(item, "The item may not be null");

    if (getOrientationInvariantAxis(axis) == Axis.DRAGGING_AXIS) {
        Toolbar[] toolbars = getTabSwitcher().getToolbars();
        animator.y((getTabSwitcher().areToolbarsShown() && getTabSwitcher().isSwitcherShown() &&
                toolbars != null ?
                toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX].getHeight() - tabInset : 0) +
                (includePadding ? getTabSwitcherPadding(axis, Gravity.START) : 0) + position);
    } else {
        View view = item.getView();
        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) view.getLayoutParams();
        animator.x(position + layoutParams.leftMargin + (includePadding ?
                getTabSwitcher().getPaddingLeft() / 2f -
                        getTabSwitcher().getPaddingRight() / 2f : 0) -
                (getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE &&
                        getTabSwitcher().isSwitcherShown() ?
                        stackedTabCount * stackedTabSpacing / 2f : 0));
    }
}
 
源代码4 项目: SpringActionMenu   文件: ActionMenu.java
/**
 * buttonItem open animation
 */
private void buttonItemOpenAnimation(int index,ActionButtonItems view) {
    if (index == 0) {
        view.startFactorAnimation(duration / 6, 0, 1);
    } else {
        ViewPropertyAnimator propertyAnimator = view.animate().alpha(1).
                setInterpolator(new OvershootInterpolator()).setDuration(duration / 3);

        switch (expandDirect) {
            case expandDirectTop:
                propertyAnimator.y((circleRadius * 2 + dimens) * (childViewCount - 1 - index) + circleRadius * 2);
                break;
            case expandDirectDown:
                propertyAnimator.y(circleRadius * 2 * index + dimens * (index - 1));
                break;
            case expandDirectLeft:
                propertyAnimator.x((circleRadius * 2 + dimens) * (childViewCount - 1 - index) + circleRadius * 2);
                break;
            case expandDirectRight:
                propertyAnimator.x(circleRadius * 2 * index + dimens * (index - 1));
                break;
        }
        if (isOpen) {
            view.setVisibility(View.VISIBLE);
        }

        propertyAnimator.start();

        // start factor animation
        view.startFactorAnimation(duration / 6, 0, -1);
    }
    view.setOpen(isOpen);
}
 
源代码5 项目: MiBandDecompiled   文件: g.java
public com.nineoldandroids.view.ViewPropertyAnimator x(float f)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.x(f);
    }
    return this;
}