Example usage for android.view View setX

List of usage examples for android.view View setX

Introduction

In this page you can find the example usage for android.view View setX.

Prototype

public void setX(float x) 

Source Link

Document

Sets the visual x position of this view, in pixels.

Usage

From source file:Main.java

public static void setViewX(View view, float originalX, float finalX, float percent) {
    float calcX = (finalX - originalX) * percent + originalX;
    view.setX(calcX);
}

From source file:Main.java

public static void setX(View view, int x) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        view.setX(x);
    } else {/* www .j  ava2 s . c  o  m*/
        ViewGroup.MarginLayoutParams marginParams = getOrCreateMarginLayoutParams(view);
        marginParams.leftMargin = x - view.getLeft();
        view.setLayoutParams(marginParams);
    }
}

From source file:Main.java

public static void linearAnimation(final View view, final int startX, final int startY, final int endX,
        final int endY, long duration, final Runnable callback) {
    Animation anim = new TranslateAnimation(startX, endX, startY, endY);
    anim.setDuration(duration);//from w  w  w  .  j a  v a 2s  . c o m
    anim.setInterpolator(new DecelerateInterpolator());
    view.startAnimation(anim);

    anim.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.clearAnimation();
            view.setX(view.getX() + endX);
            view.setY(view.getY() + endY);

            if (callback != null)
                callback.run();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
}

From source file:io.github.hidroh.materialistic.widget.NavFloatingActionButton.java

@Synthetic
void startDrag(float startX, float startY) {
    mVibrator.vibrate(VIBRATE_DURATION_MS * 2);
    Toast.makeText(getContext(), R.string.hint_drag, Toast.LENGTH_SHORT).show();
    //noinspection Convert2Lambda
    super.setOnTouchListener(new OnTouchListener() {
        @SuppressLint("ClickableViewAccessibility")
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override/*from   w w  w .  j a v a 2 s.  c o  m*/
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_MOVE:
                view.setX(motionEvent.getRawX() - startX); // TODO compensate shift
                view.setY(motionEvent.getRawY() - startY);
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                bindNavigationPad();
                break;
            default:
                return false;
            }
            return true;
        }
    });
}

From source file:com.jaspersoft.android.jaspermobile.widget.DraggableViewsContainer.java

@Override
public boolean onDrag(View v, DragEvent event) {
    int viewId;/*w w  w. j av  a  2s  .com*/
    View noteView;
    switch (event.getAction()) {
    case DragEvent.ACTION_DRAG_STARTED:
        viewId = Integer.parseInt(event.getClipDescription().getLabel().toString());
        noteView = findViewById(viewId);
        noteView.setVisibility(View.GONE);
        return true;
    case DragEvent.ACTION_DROP:
        viewId = Integer.parseInt(event.getClipDescription().getLabel().toString());
        noteView = findViewById(viewId);
        noteView.setX(event.getX() - noteView.getWidth() / 2);
        noteView.setY(event.getY() - noteView.getHeight() / 2);
        noteView.setVisibility(View.VISIBLE);
        return true;
    default:
        return false;
    }
}

From source file:ca.zadrox.dota2esportticker.ui.LiveContentView.java

private void initMapView() {
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();

    int minHeight = displayMetrics.widthPixels > displayMetrics.heightPixels
            ? displayMetrics.heightPixels - UIUtils.calculateActionBarSize(this)
            : displayMetrics.widthPixels;

    mapX = mapY = minHeight - getResources().getDimensionPixelSize(R.dimen.keyline_1) * 2;

    Picasso.with(this).load(R.drawable.dota2_map).config(Bitmap.Config.RGB_565).resize(mapX, mapY).into(mapView,
            mLoadMapCallback);/* w  ww .j a  v a2  s. c o m*/

    for (int i = 0; i < DotaMapModel.DIRE_TOWERS.length; i++) {
        int x = DotaMapModel.scaleToNewMapSize(DotaMapModel.DIRE_TOWERS_X[i], mapX);
        int y = DotaMapModel.scaleToNewMapSize(DotaMapModel.DIRE_TOWERS_Y[i], mapY);

        View v = findViewById(DotaMapModel.DIRE_TOWERS[i]);
        v.setX(x);
        v.setY(y);
        v.setBackground(getResources().getDrawable(R.drawable.dire_tower));
    }

    for (int i = 0; i < DotaMapModel.DIRE_STRUCTURES.length; i++) {
        int x = DotaMapModel.scaleToNewMapSize(DotaMapModel.DIRE_STRUCTURES_X[i], mapX);
        int y = DotaMapModel.scaleToNewMapSize(DotaMapModel.DIRE_STRUCTURES_Y[i], mapY);

        View v = findViewById(DotaMapModel.DIRE_STRUCTURES[i]);
        v.setX(x);
        v.setY(y);
        v.setBackground(getResources().getDrawable(R.drawable.dire_hero_oval));
    }

    for (int i = 0; i < DotaMapModel.RADIANT_TOWERS.length; i++) {
        int x = DotaMapModel.scaleToNewMapSize(DotaMapModel.RADIANT_TOWERS_X[i], mapX);
        int y = DotaMapModel.scaleToNewMapSize(DotaMapModel.RADIANT_TOWERS_Y[i], mapY);

        View v = findViewById(DotaMapModel.RADIANT_TOWERS[i]);
        v.setX(x);
        v.setY(y);
        v.setBackground(getResources().getDrawable(R.drawable.radiant_tower));
    }

    for (int i = 0; i < DotaMapModel.RADIANT_STRUCTURES.length; i++) {
        int x = DotaMapModel.scaleToNewMapSize(DotaMapModel.RADIANT_STRUCTURES_X[i], mapX);
        int y = DotaMapModel.scaleToNewMapSize(DotaMapModel.RADIANT_STRUCTURES_Y[i], mapY);

        View v = findViewById(DotaMapModel.RADIANT_STRUCTURES[i]);
        v.setX(x);
        v.setY(y);
        v.setBackground(getResources().getDrawable(R.drawable.radiant_hero_oval));
    }

    final int iconSizeRoshan = Math.round(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()));

    ImageView v = (ImageView) findViewById(DotaMapModel.ROSHAN);
    v.setX(DotaMapModel.scaleToNewMapSize(DotaMapModel.ROSHAN_X, mapX));
    v.setY(DotaMapModel.scaleToNewMapSize(DotaMapModel.ROSHAN_Y, mapY));

    Picasso.with(this).load(R.drawable.drawable_map_roshan).resize(iconSizeRoshan, iconSizeRoshan).centerCrop()
            .into(v);
}

From source file:com.appolica.interactiveinfowindow.InfoWindowManager.java

private void centerInfoWindow(@NonNull final InfoWindow infoWindow, @NonNull final View container) {
    final InfoWindow.MarkerSpecification markerSpec = infoWindow.getMarkerSpec();
    final Projection projection = googleMap.getProjection();

    final Point windowScreenLocation = projection.toScreenLocation(infoWindow.getPosition());

    final int containerWidth = container.getWidth();
    final int containerHeight = container.getHeight();

    final int x;
    if (markerSpec.centerByX()) {
        x = windowScreenLocation.x - containerWidth / 2;
    } else {//from  w  w  w .j  a v  a2s  . c o  m
        x = windowScreenLocation.x + markerSpec.getOffsetX();
    }

    final int y;
    if (markerSpec.centerByY()) {
        y = windowScreenLocation.y - containerHeight / 2;
    } else {
        y = windowScreenLocation.y - containerHeight - markerSpec.getOffsetY();
    }

    final int pivotX = containerWidth / 2;
    final int pivotY = containerHeight;

    container.setPivotX(pivotX);
    container.setPivotY(pivotY);

    container.setX(x);
    container.setY(y);
}

From source file:org.protocoderrunner.apprunner.api.PUI.java

public void draggable(View v) {
    v.setOnTouchListener(new OnTouchListener() {
        PointF downPT = new PointF(); // Record Mouse Position When Pressed
        // Down//from w ww  . j av a2s. com
        PointF startPT = new PointF(); // Record Start Position of 'img'

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int eid = event.getAction();
            switch (eid) {
            case MotionEvent.ACTION_MOVE:
                PointF mv = new PointF(event.getX() - downPT.x, event.getY() - downPT.y);
                v.setX((int) (startPT.x + mv.x));
                v.setY((int) (startPT.y + mv.y));
                startPT = new PointF(v.getX(), v.getY());
                break;
            case MotionEvent.ACTION_DOWN:
                downPT.x = event.getX();
                downPT.y = event.getY();
                startPT = new PointF(v.getX(), v.getY());
                break;
            case MotionEvent.ACTION_UP:
                // Nothing have to do
                break;
            default:
                break;
            }
            return true;
        }
    });

}

From source file:com.android.launcher2.PagedView.java

protected void scrollToNewPageWithoutMovingPages(int newCurrentPage) {
    int newX = getChildOffset(newCurrentPage) - getRelativeChildOffset(newCurrentPage);
    int delta = newX - getScrollX();

    final int pageCount = getChildCount();
    for (int i = 0; i < pageCount; i++) {
        View page = (View) getPageAt(i);
        page.setX(page.getX() + delta);
    }//w w w. j a  v  a 2 s.  c o m
    setCurrentPage(newCurrentPage);
}

From source file:com.android.launcher2.PagedView.java

public void setLayoutScale(float childrenScale) {
    mLayoutScale = childrenScale;//from w  w  w.  ja va 2s .c o m
    invalidateCachedOffsets();

    // Now we need to do a re-layout, but preserving absolute X and Y coordinates
    int childCount = getChildCount();
    float childrenX[] = new float[childCount];
    float childrenY[] = new float[childCount];
    for (int i = 0; i < childCount; i++) {
        final View child = getPageAt(i);
        childrenX[i] = child.getX();
        childrenY[i] = child.getY();
    }
    // Trigger a full re-layout (never just call onLayout directly!)
    int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
    int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
    requestLayout();
    measure(widthSpec, heightSpec);
    layout(getLeft(), getTop(), getRight(), getBottom());
    for (int i = 0; i < childCount; i++) {
        final View child = getPageAt(i);
        child.setX(childrenX[i]);
        child.setY(childrenY[i]);
    }

    // Also, the page offset has changed  (since the pages are now smaller);
    // update the page offset, but again preserving absolute X and Y coordinates
    scrollToNewPageWithoutMovingPages(mCurrentPage);
}