static void setX(View view, float x) { view.setX(x); }
@Override public void setX(float x) { View targetView; if ((targetView = getTargetView()) != null){ targetView.setX(x); } }
@Override public void set(Object mountContent, float value) { if (mountContent instanceof LithoView) { ((View) mountContent).setX(value); } else if (mountContent instanceof View) { final View view = (View) mountContent; float parentX = getPositionRelativeToLithoView((View) view.getParent(), true); view.setX(value - parentX); } else if (mountContent instanceof Drawable) { final Drawable drawable = (Drawable) mountContent; float parentX = getPositionRelativeToLithoView(getHostView(drawable), true); BoundsHelper.applyXYToDrawableForAnimation( drawable, (int) (value - parentX), drawable.getBounds().top); } else { throw new UnsupportedOperationException( "Setting X on unsupported mount content: " + mountContent); } }
public void setInnViewPositionX(int x) { if (mInnViewPositionX == x) { return; } mInnerView.setX(x); mInnViewPositionX = (int) x; if (mWallpaperViewerLisenter != null) { float percent = ((float) x - mInnCenterPositionX) / ((float) mInnCenterPositionX); // 粗力度化防止抖动 percent = ((float) ((int) (percent * 50)) / 50); if (mMovePercents != percent) { mMovePercents = percent; mWallpaperViewerLisenter.onWallpaperViewerScroll(percent); } } }
@Override public boolean onTouch(View v, MotionEvent event) { View target = findViewById(R.id.blur_frame); if (event.getAction() == MotionEvent.ACTION_DOWN) { dx = target.getX() - event.getRawX(); dy = target.getY() - event.getRawY(); } else if (event.getAction() == MotionEvent.ACTION_MOVE) { target.setX(event.getRawX() + dx); target.setY(event.getRawY() + dy); } return true; } };
@Override public void update(View view, float value) { if (view == null) { return; } float[] currentPosition = new float[2]; pathMeasure.getPosTan(value, currentPosition, null); final float x = currentPosition[0]; final float y = currentPosition[1]; view.setX(x); view.setY(y); Log.d(null, "path: value=" + value + ", x=" + x + ", y=" + y); } }, 0, pathMeasure.getLength());
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_MOVE: mMoved = true; view.setX(motionEvent.getRawX() - startX); // TODO compensate shift view.setY(motionEvent.getRawY() - startY); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: bindNavigationPad(); if (mMoved) { persistPosition(); } break; default: return false; } return true; } });
case X: v.setX(value); break; case Y:
/** * 爱心运动轨迹的动画实现 */ private ValueAnimator getBezierAnimtor(final View target) { BezierEvaluator evaluator = new BezierEvaluator(getPoint(2), getPoint(1)); ValueAnimator animator = ValueAnimator.ofObject(evaluator, new PointF((measuredWidth - drawableWidth) / 2, measuredHeight - drawableHeight), new PointF(mRandom.nextInt(getWidth()), 0)); animator.setDuration(3000); animator.setTarget(target); animator.addUpdateListener(valueAnimator -> { //获取贝塞尔曲线的运动轨迹 让爱心跟随着移动 PointF animatedValue = (PointF) valueAnimator.getAnimatedValue(); target.setX(animatedValue.x); target.setY(animatedValue.y); //增加透明度的变化 target.setAlpha(1 - valueAnimator.getAnimatedFraction()); }); return animator; }
final int avatarTopest = avatarHalf + avatarVOffset; avatar.setX(avatarHOffset + avatarRightest * ratio); avatar.setY(avatarVOffset - avatarTopest * ratio); avatar.setScaleX(0.5f + 0.5f * ratio); texts.setScaleY(0.8f + 0.2f * ratio); for (int i = 0; i < textStart.size(); i++) { texts.getChildAt(i).setX(textStart.get(i) * ratio);
@Override public void onGlobalLayout() { mapSwitcher.getViewTreeObserver().removeOnGlobalLayoutListener(this); final int viewLeft = mapSwitcher.getLeft(); final int viewTop = mapSwitcher.getTop() + mapSwitcher.getHeight() / 3; final int border = 100; final int xRange = Math.max(1, mapSwitcher.getWidth() - border * 2); final int yRange = Math.max(1, (mapSwitcher.getHeight() / 3) * 2 - border * 2); final Random rnd = new Random(); for (int i = 0, cnt = dotCoords.length; i < cnt; i++) { dotCoords[i][0] = viewLeft + border + rnd.nextInt(xRange); dotCoords[i][1] = viewTop + border + rnd.nextInt(yRange); } greenDot = findViewById(R.id.green_dot); greenDot.setX(dotCoords[0][0]); greenDot.setY(dotCoords[0][1]); } });
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (isFirst) { for (int i = 0; i < mViewPager.getChildCount(); i++) { View v = mViewPager.getChildAt(i).findViewById(R.id.ll_bottom); v.setY(mViewPager.getChildAt(i).findViewById(R.id.imageView).getHeight()); v.setX(MarginConfig.MARGIN_LEFT_RIGHT); //触发一次dependency变化,让按钮归位 mZoomHeader.setY(mZoomHeader.getY() - 1); isFirst = false; } } //隐藏底部栏] bottomY = (int) mBottomView.getY(); mBottomView.setTranslationY(mBottomView.getY() + mBottomView.getHeight()); mZoomHeader.setBottomView(mBottomView, bottomY); }
public void isComingToFinish() { if (mRotateScreen) { mCloseFlagForDetached = true; mCloseFlagForWindowFocus = false; mOnInternalStateListener.onClose(null); mPreContentView.setX(0); } }
private void offsetAndScaleButtons(float centerX, float centerY, float angleStep, float offset, float scale) { for (int i = 0, cnt = mButtons.size(); i < cnt; i++) { final float angle = angleStep * i - 90; final float x = (float) Math.cos(Math.toRadians(angle)) * offset; final float y = (float) Math.sin(Math.toRadians(angle)) * offset; final View button = mButtons.get(i); button.setX(centerX + x); button.setY(centerY + y); button.setScaleX(1.0f * scale); button.setScaleY(1.0f * scale); } }
@Override public void onGlobalLayout() { View view = contentViewRecycler.getView(tab); if (view != null) { view.setX(0); } }
@Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float valueX = Float.parseFloat(valueAnimator.getAnimatedValue().toString()); View afterChild; for (int i = chooseIndex + 1; i < getChildCount(); i++) { afterChild = getChildAt(i); afterChild.setX(currX[i - chooseIndex - 1] + valueX); } } });
void setDegree(float degree) { mValue = degree; View clipView = mTarget.get(); float x = mArcMetric.getAxisPoint().x + mArcMetric.mRadius * Utils.cos(degree); float y = mArcMetric.getAxisPoint().y - mArcMetric.mRadius * Utils.sin(degree); clipView.setX(x - clipView.getWidth() / 2); clipView.setY(y - clipView.getHeight() / 2); }