Java Code Examples for android.view.View.setX()

The following are Jave code examples for showing how to use setX() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ChromeLikeTabSwitcher   File: TabletTabSwitcherLayout.java   Source Code and License Vote up 8 votes
/**
 * Creates and returns a layout listener, which allows to position a tab, which is a neighbor of
 * the currently selected tab, when swiping horizontally.
 *
 * @param neighbor
 *         The tab item, which corresponds to the neighboring tab, as an instance of the class
 *         {@link TabItem}. The tab item may not be null
 * @param dragDistance
 *         The distance of the swipe gesture in pixels as a {@link Float} value
 * @return The layout listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The layout listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createSwipeNeighborLayoutListener(
        @NonNull final TabItem neighbor, final float dragDistance) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = contentViewRecycler.getView(neighbor.getTab());

            if (view != null) {
                float position;

                if (dragDistance > 0) {
                    position = -getTabSwitcher().getWidth() + dragDistance - swipedTabDistance;
                } else {
                    position = getTabSwitcher().getWidth() + dragDistance + swipedTabDistance;
                }

                view.setX(position);
            }
        }

    };
}
 
Example 2
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   Source Code and License Vote up 7 votes
/**
 * Creates and returns a layout listener, which allows to show a tab as the currently selected
 * one, once it view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, which has been added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
@NonNull
private OnGlobalLayoutListener createAddSelectedTabLayoutListener(
        @NonNull final AbstractItem item) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            View view = item.getView();
            FrameLayout.LayoutParams layoutParams =
                    (FrameLayout.LayoutParams) view.getLayoutParams();
            view.setAlpha(1f);
            getArithmetics().setPivot(Axis.DRAGGING_AXIS, item,
                    getArithmetics().getPivot(Axis.DRAGGING_AXIS, item, DragState.NONE));
            getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item,
                    getArithmetics().getPivot(Axis.ORTHOGONAL_AXIS, item, DragState.NONE));
            view.setX(layoutParams.leftMargin);
            view.setY(layoutParams.topMargin);
            getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 1);
            getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 1);
        }

    };
}
 
Example 3
Project: ChromeLikeTabSwitcher   File: TabletArithmetics.java   Source Code and License Vote up 7 votes
@Override
public final void setPosition(@NonNull final Axis axis, @NonNull final AbstractItem item,
                              final float position) {
    ensureNotNull(axis, "The axis may not be null");
    ensureNotNull(item, "The item may not be null");
    View view = item.getView();

    if (axis == Axis.DRAGGING_AXIS) {
        Toolbar[] toolbars = getTabSwitcher().getToolbars();
        view.setX((getTabSwitcher().areToolbarsShown() && toolbars != null ? Math.max(0,
                toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX].getWidth() - tabOffset) : 0) +
                position);
    } else {
        view.setY((tabContainerHeight - tabHeight) + position);
    }
}
 
Example 4
Project: AndroidSimpleViews   File: SimpleViewPager.java   Source Code and License Vote up 7 votes
private void initChild(int l, int t, int r, int b) {
    int clientCount = getChildCount();
    mPagerView.bringToFront();
    mActiveView = getChildAt(mActiveChildIndex);
    for (int i = 0; i < clientCount; i++) {
        View child = getChildAt(i);
        if (child == mPagerView) {
            child.setX(0);
            continue;
        }
        if (mNew) {
            child.setX(child == mActiveView ? 0 : getWidth());
        }
    }
    mNew = false;

}
 
Example 5
Project: CoordinatorBehavior   File: ImageBehavior.java   Source Code and License Vote up 7 votes
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    maybeInitProperties((ImageView) child, dependency);

    final int maxScrollDistance = (int) (startToolbarPosition - getStatusBarHeight());
    float expandedPercentageFactor = dependency.getY() / maxScrollDistance;

    float distanceYToSubtract = ((startYPosition - finalYPosition)
            * (1f - expandedPercentageFactor)) + (child.getHeight() / 2);

    float distanceXToSubtract = ((startXPosition - finalXPosition)
            * (1f - expandedPercentageFactor)) + (child.getWidth() / 2);

    float heightToSubtract = ((startHeight - finalHeight) * (1f - expandedPercentageFactor));

    child.setY(startYPosition - distanceYToSubtract);
    child.setX(startXPosition - distanceXToSubtract);

    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
    lp.width = (int) (startHeight - heightToSubtract);
    lp.height = (int) (startHeight - heightToSubtract);
    child.setLayoutParams(lp);
    return true;
}
 
Example 6
Project: Sunstrike   File: SunStrike.java   Source Code and License Vote up 6 votes
private void addHiddenViews() {
    for (int indexHiddenView : indexHiddenViews) {
        View hiddenView = animationLayout.getChildAt(indexHiddenView);
        hiddenView.setX(mainView.getX());
        hiddenView.setY(mainView.getY());
        animationController.addHiddenView(hiddenView);
    }
    animationController.generateHandler();
}
 
Example 7
Project: SunmiUI   File: BannerLayout.java   Source Code and License Vote up 6 votes
private boolean actionMove(MotionEvent event, Banner banner) {
    View bannerView = banner.view;
    mXMove = event.getRawX();
    int scrolledX = (int) (mXLastMove - mXMove);
    Banner bannerNew = looper.changeRunningManByScrollDirection(scrolledX);
    if(banner.position!=bannerNew.position){
        banner = bannerNew;
        bannerView = banner.view;
        mXDownView = bannerView.getX();
    }

    LogUtil.d(TAG, "onTouchEvent scrolledX:"+scrolledX + " bannerView.getScrollX():"+bannerView.getScrollX()+" banner.exitEndX:"+banner.exitEndX+" banner.enterEndX:"+banner.enterEndX + " bannerView.getWidth():"+bannerView.getWidth());
    LogUtil.d(TAG, "onTouchEvent bannerView.getTranslationX():"+bannerView.getTranslationX()+" bannerView.getX():"+bannerView.getX());
    if (bannerView.getX()-scrolledX < banner.exitEndX) { //左滑到底
        bannerView.setX(banner.exitEndX);
        edgeGlowOnPull(event);
        return true;
    } else if (bannerView.getX()-scrolledX > banner.enterEndX ) { //右滑到底
        bannerView.setX(banner.enterEndX);
        edgeGlowOnPull(event);
        return true;
    }

    LogUtil.d(TAG, "滑动 bannerView.offsetLeftAndRight:"+-scrolledX);
    bannerView.offsetLeftAndRight(-scrolledX);
    LogUtil.d(TAG1,  " bannerView.getScrollX():"+bannerView.getScrollX()+" bannerView.getTranslationX():"+bannerView.getTranslationX()+" bannerView.getX():"+bannerView.getX()+" bannerView.getLeft():"+bannerView.getLeft());

    mXLastMove = mXMove;
    return false;
}
 
Example 8
Project: andcoachmark   File: TopOfCircleActionDescriptionRenderer.java   Source Code and License Vote up 6 votes
@Override
public void render(CoachmarkViewLayout layout, View actionDescription, View actionArrow) {

    RectF circleRectangle = layout.calcCircleRectF();

    actionDescription.setX(circleRectangle.centerX() - (actionDescription.getWidth() / 2));
    actionDescription.setY(circleRectangle.top - actionArrow.getHeight() - actionDescription.getHeight());

    actionArrow.setRotation(90);
    actionArrow.setX(circleRectangle.centerX() - (actionArrow.getWidth() / 2));
    actionArrow.setY(circleRectangle.top - actionArrow.getHeight());
}
 
Example 9
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   Source Code and License Vote up 6 votes
/**
 * Starts a peek animation to add a specific tab.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param duration
 *         The duration of the animation in milliseconds as a {@link Long} value
 * @param interpolator
 *         The interpolator, which should be used by the animation, as an instance of the type
 *         {@link Interpolator}. The interpolator may not be null
 * @param peekPosition
 *         The position on the dragging axis, the tab should be moved to, in pixels as a {@link
 *         Float} value
 * @param peekAnimation
 *         The peek animation, which has been used to add the tab, as an instance of the class
 *         {@link PeekAnimation}. The peek animation may not be null
 */
private void animatePeek(@NonNull final AbstractItem item, final long duration,
                         @NonNull final Interpolator interpolator, final float peekPosition,
                         @NonNull final PeekAnimation peekAnimation) {
    PhoneTabViewHolder viewHolder = (PhoneTabViewHolder) ((TabItem) item).getViewHolder();
    viewHolder.closeButton.setVisibility(View.GONE);
    View view = item.getView();
    float x = peekAnimation.getX();
    float y = peekAnimation.getY() + tabTitleContainerHeight;
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
    view.setAlpha(1f);
    getArithmetics().setPivot(Axis.X_AXIS, item, x);
    getArithmetics().setPivot(Axis.Y_AXIS, item, y);
    view.setX(layoutParams.leftMargin);
    view.setY(layoutParams.topMargin);
    getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 0);
    getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 0);
    ViewPropertyAnimator animation = view.animate();
    animation.setInterpolator(interpolator);
    animation.setListener(
            new AnimationListenerWrapper(createPeekAnimationListener(item, peekAnimation)));
    animation.setStartDelay(0);
    animation.setDuration(duration);
    getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation, 1);
    getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation, 1);
    getArithmetics().animatePosition(Axis.DRAGGING_AXIS, animation, item, peekPosition, true);
    animation.start();
    int selectedTabIndex = getModel().getSelectedTabIndex();
    TabItem selectedItem = TabItem.create(getModel(), tabViewRecycler, selectedTabIndex);
    tabViewRecycler.inflate(selectedItem);
    selectedItem.getTag().setPosition(0);
    PhoneTabViewHolder selectedTabViewHolder =
            (PhoneTabViewHolder) selectedItem.getViewHolder();
    selectedTabViewHolder.closeButton.setVisibility(View.GONE);
    animateShowSwitcher(selectedItem, duration, interpolator,
            createZoomOutAnimationListener(selectedItem, peekAnimation));
}
 
Example 10
Project: PlusGram   File: ViewProxy.java   Source Code and License Vote up 6 votes
public static void setX(View view, float x) {
    if (View10.NEED_PROXY) {
        View10.wrap(view).setX(x);
    } else {
        view.setX(x);
    }
}
 
Example 11
Project: boohee_v5.6   File: ViewHelper.java   Source Code and License Vote up 5 votes
static void setX(View view, float x) {
    view.setX(x);
}
 
Example 12
Project: GitHub   File: WoWoPosition3DAnimation.java   Source Code and License Vote up 5 votes
@Override
protected void toEndState(View view) {
    view.setX(toX);
    view.setY(toY);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) view.setZ(toZ);
}
 
Example 13
Project: RNLearn_Project1   File: PositionAnimationPairPropertyUpdater.java   Source Code and License Vote up 5 votes
@Override
protected void setProperty(View view, float[] propertyValues) {
  view.setX(propertyValues[0] - 0.5f * view.getWidth());
  view.setY(propertyValues[1] - 0.5f * view.getHeight());
}
 
Example 14
Project: android-project-gallery   File: ViewHelper.java   Source Code and License Vote up 5 votes
static void setX(View view, float x) {
    view.setX(x);
}
 
Example 15
Project: RNLearn_Project1   File: PositionAnimationPairPropertyUpdater.java   Source Code and License Vote up 5 votes
@Override
protected void setProperty(View view, float[] propertyValues) {
  view.setX(propertyValues[0] - 0.5f * view.getWidth());
  view.setY(propertyValues[1] - 0.5f * view.getHeight());
}
 
Example 16
Project: ChromeLikeTabSwitcher   File: PhoneTabSwitcherLayout.java   Source Code and License Vote up 5 votes
/**
 * Animates the position and size of a specific tab in order to show the tab switcher.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be animated, as an instance of
 *         the class {@link AbstractItem}. The item may not be null
 * @param duration
 *         The duration of the animation in milliseconds as a {@link Long} value
 * @param interpolator
 *         The interpolator, which should be used by the animation, as an instance of the type
 *         {@link Interpolator}. The interpolator may not be null
 * @param listener
 *         The listener, which should be notified about the animation's progress, as an instance
 *         of the type {@link AnimatorListener} or null, if no listener should be notified
 */
private void animateShowSwitcher(@NonNull final AbstractItem item, final long duration,
                                 @NonNull final Interpolator interpolator,
                                 @Nullable final AnimatorListener listener) {
    View view = item.getView();
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
    view.setX(layoutParams.leftMargin);
    view.setY(layoutParams.topMargin);
    getArithmetics().setScale(Axis.DRAGGING_AXIS, item, 1);
    getArithmetics().setScale(Axis.ORTHOGONAL_AXIS, item, 1);
    getArithmetics().setPivot(Axis.DRAGGING_AXIS, item,
            getArithmetics().getPivot(Axis.DRAGGING_AXIS, item, DragState.NONE));
    getArithmetics().setPivot(Axis.ORTHOGONAL_AXIS, item,
            getArithmetics().getPivot(Axis.ORTHOGONAL_AXIS, item, DragState.NONE));
    float scale = getArithmetics().getScale(item, true);
    int selectedTabIndex = getModel().getSelectedTabIndex();

    if (item.getIndex() < selectedTabIndex) {
        getArithmetics().setPosition(Axis.DRAGGING_AXIS, item,
                getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS));
    } else if (item.getIndex() > selectedTabIndex) {
        getArithmetics().setPosition(Axis.DRAGGING_AXIS, item,
                getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE ? 0 :
                        layoutParams.topMargin);
    }

    if (tabViewBottomMargin == -1) {
        tabViewBottomMargin = calculateBottomMargin(item);
    }

    animateBottomMargin(view, tabViewBottomMargin, duration, 0);
    ViewPropertyAnimator animation = view.animate();
    animation.setDuration(duration);
    animation.setInterpolator(interpolator);
    animation.setListener(new AnimationListenerWrapper(listener));
    getArithmetics().animateScale(Axis.DRAGGING_AXIS, animation, scale);
    getArithmetics().animateScale(Axis.ORTHOGONAL_AXIS, animation, scale);
    getArithmetics()
            .animatePosition(Axis.DRAGGING_AXIS, animation, item, item.getTag().getPosition(),
                    true);
    getArithmetics().animatePosition(Axis.ORTHOGONAL_AXIS, animation, item, 0, true);
    animation.setStartDelay(0);
    animation.start();
}
 
Example 17
Project: android-project-gallery   File: ViewPropertyAnimatorHC.java   Source Code and License Vote up 5 votes
/**
 * This method handles setting the property values directly in the View object's fields.
 * propertyConstant tells it which property should be set, value is the value to set
 * the property to.
 *
 * @param propertyConstant The property to be set
 * @param value The value to set the property to
 */
private void setValue(int propertyConstant, float value) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //info.mTranslationX = value;
                v.setTranslationX(value);
                break;
            case TRANSLATION_Y:
                //info.mTranslationY = value;
                v.setTranslationY(value);
                break;
            case ROTATION:
                //info.mRotation = value;
                v.setRotation(value);
                break;
            case ROTATION_X:
                //info.mRotationX = value;
                v.setRotationX(value);
                break;
            case ROTATION_Y:
                //info.mRotationY = value;
                v.setRotationY(value);
                break;
            case SCALE_X:
                //info.mScaleX = value;
                v.setScaleX(value);
                break;
            case SCALE_Y:
                //info.mScaleY = value;
                v.setScaleY(value);
                break;
            case X:
                //info.mTranslationX = value - v.mLeft;
                v.setX(value);
                break;
            case Y:
                //info.mTranslationY = value - v.mTop;
                v.setY(value);
                break;
            case ALPHA:
                //info.mAlpha = value;
                v.setAlpha(value);
                break;
        }
    }
}
 
Example 18
Project: exciting-app   File: ViewPropertyAnimatorHC.java   Source Code and License Vote up 5 votes
/**
 * This method handles setting the property values directly in the View object's fields.
 * propertyConstant tells it which property should be set, value is the value to set
 * the property to.
 *
 * @param propertyConstant The property to be set
 * @param value The value to set the property to
 */
private void setValue(int propertyConstant, float value) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //info.mTranslationX = value;
                v.setTranslationX(value);
                break;
            case TRANSLATION_Y:
                //info.mTranslationY = value;
                v.setTranslationY(value);
                break;
            case ROTATION:
                //info.mRotation = value;
                v.setRotation(value);
                break;
            case ROTATION_X:
                //info.mRotationX = value;
                v.setRotationX(value);
                break;
            case ROTATION_Y:
                //info.mRotationY = value;
                v.setRotationY(value);
                break;
            case SCALE_X:
                //info.mScaleX = value;
                v.setScaleX(value);
                break;
            case SCALE_Y:
                //info.mScaleY = value;
                v.setScaleY(value);
                break;
            case X:
                //info.mTranslationX = value - v.mLeft;
                v.setX(value);
                break;
            case Y:
                //info.mTranslationY = value - v.mTop;
                v.setY(value);
                break;
            case ALPHA:
                //info.mAlpha = value;
                v.setAlpha(value);
                break;
        }
    }
}
 
Example 19
Project: android-api   File: ViewAnchor.java   Source Code and License Vote up 4 votes
/**
 * Anchors a View to a point relative to its parent. This will anchor a point on the View to a
 * point on its parent. The anchorUV is relative to the size of the View, a value of (0,0) will
 * anchor the top left corner of the view and a value of (1,1) will anchor the bottom right
 * corner of the view. Negative and values larger than 1 are also valid for anchorUV.
 *
 * @param view The View to set the position of.
 * @param screenPoint The point to anchor to, relative to the parent of the View.
 * @param anchorUV The point on the View to use as the anchor point.
 */
@UiThread
public static void positionView(@NonNull View view, @NonNull Point screenPoint, @NonNull PointF anchorUV)
{
    view.setX(screenPoint.x - (view.getWidth()  * anchorUV.x));
    view.setY(screenPoint.y - (view.getHeight() * anchorUV.y));
}
 
Example 20
Project: phonk   File: WidgetHelper.java   Source Code and License Vote up 3 votes
public static void setMovable(View viewHandler, final View viewContainer, final ReturnInterface callback) {
    View.OnTouchListener onMoveListener = new View.OnTouchListener() {

        public int x_init;
        public int y_init;

        @Override
        public boolean onTouch(View v, MotionEvent e) {
            int action = e.getActionMasked();

            switch (action) {

                case MotionEvent.ACTION_DOWN:
                    x_init = (int) e.getRawX() - (int) viewContainer.getX();
                    //MLog.network(getContext(), TAG, "" + x_init + " " + (int) e.getRawX() + " " + (int) mWindow.getX() + " " + (int) mWindow.getLeft());
                    y_init = (int) e.getRawY() - (int) viewContainer.getY();

                    break;

                case MotionEvent.ACTION_MOVE:

                    int x_cord = (int) e.getRawX();
                    int y_cord = (int) e.getRawY();

                    int posX = x_cord - x_init;
                    int posY = y_cord - y_init;

                    viewContainer.setX(posX);
                    viewContainer.setY(posY);

                    ReturnObject r = new ReturnObject();
                    r.put("x", posX);
                    r.put("y", posY);

                    if (callback != null) callback.event(r);

                    break;
            }

            return true;
        }

    };

    viewHandler.setOnTouchListener(onMoveListener);
}