android.view.View#getTranslationX ( )源码实例Demo

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

源代码1 项目: adt-leanback-support   文件: ColorOverlayDimmer.java
/**
 * Draw a dim color overlay on top of a child View inside the canvas of
 * the parent View.
 *
 * @param c Canvas of the parent View.
 * @param v A child of the parent View.
 * @param includePadding Set to true to draw overlay on padding area of the
 *        View.
 */
public void drawColorOverlay(Canvas c, View v, boolean includePadding) {
    c.save();
    float dx = v.getLeft() + v.getTranslationX();
    float dy = v.getTop() + v.getTranslationY();
    c.translate(dx, dy);
    c.concat(v.getMatrix());
    c.translate(-dx, -dy);
    if (includePadding) {
        c.drawRect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom(), mPaint);
    } else {
        c.drawRect(v.getLeft() + v.getPaddingLeft(),
                v.getTop() + v.getPaddingTop(),
                v.getRight() - v.getPaddingRight(),
                v.getBottom() - v.getPaddingBottom(), mPaint);
    }
    c.restore();
}
 
源代码2 项目: UltimateAndroid   文件: FreeFlowContainer.java
/**
 * Returns the actual frame for a view as its on stage. The FreeFlowItem's
 * frame object always represents the position it wants to be in but actual
 * frame may be different based on animation etc.
 * 
 * @param freeflowItem
 *            The freeflowItem to get the <code>Frame</code> for
 * @return The Frame for the freeflowItem or null if that view doesn't exist
 */
public Rect getActualFrame(final FreeFlowItem freeflowItem) {
	View v = freeflowItem.view;
	if (v == null) {
		return null;
	}

	Rect of = new Rect();
	of.left = (int) (v.getLeft() + v.getTranslationX());
	of.top = (int) (v.getTop() + v.getTranslationY());
	of.right = (int) (v.getRight() + v.getTranslationX());
	of.bottom = (int) (v.getBottom() + v.getTranslationY());

	return of;

}
 
源代码3 项目: Phonograph   文件: ViewUtil.java
public static boolean hitTest(View v, int x, int y) {
    final int tx = (int) (v.getTranslationX() + 0.5f);
    final int ty = (int) (v.getTranslationY() + 0.5f);
    final int left = v.getLeft() + tx;
    final int right = v.getRight() + tx;
    final int top = v.getTop() + ty;
    final int bottom = v.getBottom() + ty;

    return (x >= left) && (x <= right) && (y >= top) && (y <= bottom);
}
 
源代码4 项目: SwipeBack   文件: ViewHelper.java
public static int getRight(View v) {
    if (SwipeBack.USE_TRANSLATIONS) {
        return (int) (v.getRight() + v.getTranslationX());
    }

    return v.getRight();
}
 
源代码5 项目: Transitions-Everywhere   文件: Explode.java
@Override
public Animator onDisappear(@NonNull ViewGroup sceneRoot, @NonNull View view,
                            @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) {
    if (startValues == null) {
        return null;
    }
    Rect bounds = (Rect) startValues.values.get(PROPNAME_SCREEN_BOUNDS);
    int viewPosX = bounds.left;
    int viewPosY = bounds.top;
    float startX = view.getTranslationX();
    float startY = view.getTranslationY();
    float endX = startX;
    float endY = startY;
    int[] interruptedPosition = (int[]) startValues.view.getTag(R.id.transitionPosition);
    if (interruptedPosition != null) {
        // We want to have the end position relative to the interrupted position, not
        // the position it was supposed to start at.
        endX += interruptedPosition[0] - bounds.left;
        endY += interruptedPosition[1] - bounds.top;
        bounds.offsetTo(interruptedPosition[0], interruptedPosition[1]);
    }
    calculateOut(sceneRoot, bounds, mTempLoc);
    endX += mTempLoc[0];
    endY += mTempLoc[1];

    return TranslationAnimationCreator.createAnimation(view, startValues,
            viewPosX, viewPosY, startX, startY, endX, endY, sAccelerate, this);
}
 
源代码6 项目: android_9.0.0_r45   文件: ChangeTransform.java
public Transforms(View view) {
    translationX = view.getTranslationX();
    translationY = view.getTranslationY();
    translationZ = view.getTranslationZ();
    scaleX = view.getScaleX();
    scaleY = view.getScaleY();
    rotationX = view.getRotationX();
    rotationY = view.getRotationY();
    rotationZ = view.getRotation();
}
 
源代码7 项目: LB-Launcher   文件: CellLayout.java
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;
}
 
源代码8 项目: Transitions-Everywhere   文件: Slide.java
@Override
public float getGoneX(@NonNull ViewGroup sceneRoot, @NonNull View view) {
    final boolean isRtl = ViewUtils.isRtl(sceneRoot);
    final float x;
    if (isRtl) {
        x = view.getTranslationX() - sceneRoot.getWidth();
    } else {
        x = view.getTranslationX() + sceneRoot.getWidth();
    }
    return x;
}
 
源代码9 项目: zhangshangwuda   文件: ViewHelper.java
public static int getRight(View v) {
    if (MenuDrawer.USE_TRANSLATIONS) {
        return (int) (v.getRight() + v.getTranslationX());
    }

    return v.getRight();
}
 
源代码10 项目: opentasks   文件: BaseTaskViewDescriptor.java
@SuppressLint("NewApi")
protected void resetFlingView(View view)
{
    View flingContentView = getView(view, getFlingContentViewId());
    if (flingContentView == null)
    {
        flingContentView = view;
    }

    if (flingContentView.getTranslationX() != 0)
    {
        flingContentView.setTranslationX(0);
        flingContentView.setAlpha(1);
    }
}
 
源代码11 项目: Auie   文件: UEViewHelper.java
static float getTranslationX(View view) {
    return view.getTranslationX();
}
 
源代码12 项目: Transitions-Everywhere   文件: Translation.java
@Override
public PointF get(@NonNull View object) {
    return new PointF(object.getTranslationX(), object.getTranslationY());
}
 
源代码13 项目: RecyclerViewExtensions   文件: DragDropHelper.java
private int getViewCenterX(View view) {
    return view.getLeft() + view.getWidth() / 2 + (int) view.getTranslationX();
}
 
@Override
public PointF get(@NonNull View object) {
    return new PointF(object.getTranslationX(), object.getTranslationY());
}
 
public static int getViewLeft(View view) {
  if (Build.VERSION.SDK_INT >= 11) {
    return view.getLeft() + (int) view.getTranslationX();
  }
  return view.getLeft();
}
 
源代码16 项目: Mover   文件: ViewHelper.java
static float getTranslationX(View view) {
    return view.getTranslationX();
}
 
源代码17 项目: KJFrameForAndroid   文件: ViewHelper.java
static float getTranslationX(View view) {
    return view.getTranslationX();
}
 
源代码18 项目: Telegram   文件: FilterUsersActivity.java
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int count = getChildCount();
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int maxWidth = width - AndroidUtilities.dp(26);
    int currentLineWidth = 0;
    int y = AndroidUtilities.dp(10);
    int allCurrentLineWidth = 0;
    int allY = AndroidUtilities.dp(10);
    int x;
    for (int a = 0; a < count; a++) {
        View child = getChildAt(a);
        if (!(child instanceof GroupCreateSpan)) {
            continue;
        }
        child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(32), MeasureSpec.EXACTLY));
        if (child != removingSpan && currentLineWidth + child.getMeasuredWidth() > maxWidth) {
            y += child.getMeasuredHeight() + AndroidUtilities.dp(8);
            currentLineWidth = 0;
        }
        if (allCurrentLineWidth + child.getMeasuredWidth() > maxWidth) {
            allY += child.getMeasuredHeight() + AndroidUtilities.dp(8);
            allCurrentLineWidth = 0;
        }
        x = AndroidUtilities.dp(13) + currentLineWidth;
        if (!animationStarted) {
            if (child == removingSpan) {
                child.setTranslationX(AndroidUtilities.dp(13) + allCurrentLineWidth);
                child.setTranslationY(allY);
            } else if (removingSpan != null) {
                if (child.getTranslationX() != x) {
                    animators.add(ObjectAnimator.ofFloat(child, View.TRANSLATION_X, x));
                }
                if (child.getTranslationY() != y) {
                    animators.add(ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, y));
                }
            } else {
                child.setTranslationX(x);
                child.setTranslationY(y);
            }
        }
        if (child != removingSpan) {
            currentLineWidth += child.getMeasuredWidth() + AndroidUtilities.dp(9);
        }
        allCurrentLineWidth += child.getMeasuredWidth() + AndroidUtilities.dp(9);
    }
    int minWidth;
    if (AndroidUtilities.isTablet()) {
        minWidth = AndroidUtilities.dp(530 - 26 - 18 - 57 * 2) / 3;
    } else {
        minWidth = (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(26 + 18 + 57 * 2)) / 3;
    }
    if (maxWidth - currentLineWidth < minWidth) {
        currentLineWidth = 0;
        y += AndroidUtilities.dp(32 + 8);
    }
    if (maxWidth - allCurrentLineWidth < minWidth) {
        allY += AndroidUtilities.dp(32 + 8);
    }
    editText.measure(MeasureSpec.makeMeasureSpec(maxWidth - currentLineWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(32), MeasureSpec.EXACTLY));
    if (!animationStarted) {
        int currentHeight = allY + AndroidUtilities.dp(32 + 10);
        int fieldX = currentLineWidth + AndroidUtilities.dp(16);
        fieldY = y;
        if (currentAnimation != null) {
            int resultHeight = y + AndroidUtilities.dp(32 + 10);
            if (containerHeight != resultHeight) {
                animators.add(ObjectAnimator.ofInt(FilterUsersActivity.this, "containerHeight", resultHeight));
            }
            if (editText.getTranslationX() != fieldX) {
                animators.add(ObjectAnimator.ofFloat(editText, View.TRANSLATION_X, fieldX));
            }
            if (editText.getTranslationY() != fieldY) {
                animators.add(ObjectAnimator.ofFloat(editText, View.TRANSLATION_Y, fieldY));
            }
            editText.setAllowDrawCursor(false);
            currentAnimation.playTogether(animators);
            currentAnimation.start();
            animationStarted = true;
        } else {
            containerHeight = currentHeight;
            editText.setTranslationX(fieldX);
            editText.setTranslationY(fieldY);
        }
    } else if (currentAnimation != null) {
        if (!ignoreScrollEvent && removingSpan == null) {
            editText.bringPointIntoView(editText.getSelectionStart());
        }
    }
    setMeasuredDimension(width, containerHeight);
}
 
源代码19 项目: NotificationPeekPort   文件: SwipeHelper.java
private float getTranslation(View v) {
    return mSwipeDirection == X ? v.getTranslationX() : v.getTranslationY();
}
 
源代码20 项目: TelePlus-Android   文件: InviteContactsActivity.java
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int count = getChildCount();
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int maxWidth = width - AndroidUtilities.dp(32);
    int currentLineWidth = 0;
    int y = AndroidUtilities.dp(12);
    int allCurrentLineWidth = 0;
    int allY = AndroidUtilities.dp(12);
    int x;
    for (int a = 0; a < count; a++) {
        View child = getChildAt(a);
        if (!(child instanceof GroupCreateSpan)) {
            continue;
        }
        child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(32), MeasureSpec.EXACTLY));
        if (child != removingSpan && currentLineWidth + child.getMeasuredWidth() > maxWidth) {
            y += child.getMeasuredHeight() + AndroidUtilities.dp(12);
            currentLineWidth = 0;
        }
        if (allCurrentLineWidth + child.getMeasuredWidth() > maxWidth) {
            allY += child.getMeasuredHeight() + AndroidUtilities.dp(12);
            allCurrentLineWidth = 0;
        }
        x = AndroidUtilities.dp(16) + currentLineWidth;
        if (!animationStarted) {
            if (child == removingSpan) {
                child.setTranslationX(AndroidUtilities.dp(16) + allCurrentLineWidth);
                child.setTranslationY(allY);
            } else if (removingSpan != null) {
                if (child.getTranslationX() != x) {
                    animators.add(ObjectAnimator.ofFloat(child, "translationX", x));
                }
                if (child.getTranslationY() != y) {
                    animators.add(ObjectAnimator.ofFloat(child, "translationY", y));
                }
            } else {
                child.setTranslationX(x);
                child.setTranslationY(y);
            }
        }
        if (child != removingSpan) {
            currentLineWidth += child.getMeasuredWidth() + AndroidUtilities.dp(9);
        }
        allCurrentLineWidth += child.getMeasuredWidth() + AndroidUtilities.dp(9);
    }
    int minWidth;
    if (AndroidUtilities.isTablet()) {
        minWidth = AndroidUtilities.dp(530 - 32 - 18 - 57 * 2) / 3;
    } else {
        minWidth = (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(32 + 18 + 57 * 2)) / 3;
    }
    if (maxWidth - currentLineWidth < minWidth) {
        currentLineWidth = 0;
        y += AndroidUtilities.dp(32 + 12);
    }
    if (maxWidth - allCurrentLineWidth < minWidth) {
        allY += AndroidUtilities.dp(32 + 12);
    }
    editText.measure(MeasureSpec.makeMeasureSpec(maxWidth - currentLineWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(32), MeasureSpec.EXACTLY));
    if (!animationStarted) {
        int currentHeight = allY + AndroidUtilities.dp(32 + 12);
        int fieldX = currentLineWidth + AndroidUtilities.dp(16);
        fieldY = y;
        if (currentAnimation != null) {
            int resultHeight = y + AndroidUtilities.dp(32 + 12);
            if (containerHeight != resultHeight) {
                animators.add(ObjectAnimator.ofInt(InviteContactsActivity.this, "containerHeight", resultHeight));
            }
            if (editText.getTranslationX() != fieldX) {
                animators.add(ObjectAnimator.ofFloat(editText, "translationX", fieldX));
            }
            if (editText.getTranslationY() != fieldY) {
                animators.add(ObjectAnimator.ofFloat(editText, "translationY", fieldY));
            }
            editText.setAllowDrawCursor(false);
            currentAnimation.playTogether(animators);
            currentAnimation.start();
            animationStarted = true;
        } else {
            containerHeight = currentHeight;
            editText.setTranslationX(fieldX);
            editText.setTranslationY(fieldY);
        }
    } else if (currentAnimation != null) {
        if (!ignoreScrollEvent && removingSpan == null) {
            editText.bringPointIntoView(editText.getSelectionStart());
        }
    }
    setMeasuredDimension(width, containerHeight);
}
 
 方法所在类
 同类方法