本文整理汇总了Java中android.view.View.getTranslationX方法的典型用法代码示例。如果您正苦于以下问题:Java View.getTranslationX方法的具体用法?Java View.getTranslationX怎么用?Java View.getTranslationX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.getTranslationX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPullOverAnimation
import android.view.View; //导入方法依赖的package包/类
private void doPullOverAnimation(final View v) {
ObjectAnimator animator;
if (v.getTranslationX() + v.getWidth() / 2 + v.getLeft() > parentViewWidth / 2) {
animator = ObjectAnimator.ofFloat(v, "translationX",
v.getTranslationX(), parentViewWidth - v.getWidth()
- v.getLeft() - rightMargin - mAdjuster.right);
mTransitionX = parentViewWidth - v.getWidth() - v.getLeft() - rightMargin - mAdjuster.right;
} else {
animator = ObjectAnimator.ofFloat(v, "translationX",
v.getTranslationX(), -v.getLeft() + leftMargin + mAdjuster.left);
mTransitionX = -v.getLeft() + leftMargin + mAdjuster.left;
}
mTransitionY = (int) v.getTranslationY();
animator.setDuration(200);
animator.start();
}
示例2: onDraw
import android.view.View; //导入方法依赖的package包/类
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
for (int i = 0; i < parent.getChildCount(); i++) {
View child = parent.getChildAt(i);
if (!isHeader(child, parent)) continue;
RecyclerView.LayoutManager lm = parent.getLayoutManager();
float top = lm.getDecoratedTop(child) + child.getTranslationY();
float bottom = lm.getDecoratedBottom(child) + child.getTranslationY();
if (i == parent.getChildCount() - 1) {
// Draw to bottom if last item
bottom = Math.max(parent.getHeight(), bottom);
}
float right = lm.getDecoratedRight(child) + child.getTranslationX();
float left = lm.getDecoratedLeft(child) + child.getTranslationX();
c.drawRect(left, top, right, bottom, paint);
}
}
示例3: getValue
import android.view.View; //导入方法依赖的package包/类
private float getValue(int propertyConstant) {
View v = (View) this.mView.get();
if (v != null) {
switch (propertyConstant) {
case 1:
return v.getTranslationX();
case 2:
return v.getTranslationY();
case 4:
return v.getScaleX();
case 8:
return v.getScaleY();
case 16:
return v.getRotation();
case 32:
return v.getRotationX();
case 64:
return v.getRotationY();
case 128:
return v.getX();
case 256:
return v.getY();
case 512:
return v.getAlpha();
}
}
return 0.0f;
}
示例4: getDistance
import android.view.View; //导入方法依赖的package包/类
double getDistance() {
View view = getChildAt(0);
float left = view.getTranslationX();
float top = view.getTranslationY();
float width = view.getWidth();
float height = view.getHeight();
float w = width / 2;
float h = height / 2;
float x = left + w;
float y = top + h;
double sqrt = Math.sqrt((x - w) * (x - w) + (y - h) * (y - h));
return sqrt;
}
示例5: startAnimators
import android.view.View; //导入方法依赖的package包/类
public static void startAnimators(final View view, int startOffsetX, int startOffsetY, long delay) {
if (view.getVisibility() == View.VISIBLE && view.getAlpha() != 0f) {
view.clearAnimation();
view.animate().cancel();
final Resources res = view.getResources();
final float endAlpha = view.getAlpha();
final float endTranslateX = view.getTranslationX();
final float endTranslateY = view.getTranslationY();
view.setAlpha(0);
final Animator fade = ObjectAnimator.ofFloat(view, View.ALPHA, endAlpha);
fade.setDuration(res.getInteger(R.integer.material_in_fade_anim_duration));
fade.setInterpolator(new AccelerateInterpolator());
fade.setStartDelay(delay);
fade.start();
ViewPropertyAnimator slide = view.animate();
if (startOffsetY != 0) {
view.setTranslationY(startOffsetY);
slide.translationY(endTranslateY);
} else {
view.setTranslationX(startOffsetX);
slide.translationX(endTranslateX);
}
slide.setInterpolator(new DecelerateInterpolator(2));
slide.setDuration(res.getInteger(R.integer.material_in_slide_anim_duration));
slide.setStartDelay(delay);
slide.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
if (fade.isStarted()) {
fade.cancel();
}
view.setAlpha(endAlpha);
view.setTranslationX(endTranslateX);
view.setTranslationY(endTranslateY);
}
});
slide.start();
}
}
示例6: createArcPath
import android.view.View; //导入方法依赖的package包/类
protected Path createArcPath(View view, float endX, float endY, float radius){
Path arcPath=new Path();
float startX=view.getTranslationX();
float startY=view.getTranslationY();
float midX = startX + ((endX - startX) / 2);
float midY = startY + ((endY - startY) / 2);
float xDiff = midX - startX;
float yDiff = midY - startY;
double angle = (Math.atan2(yDiff, xDiff) * (180 / Math.PI)) - 90;
double angleRadians = Math.toRadians(angle);
float pointX = (float) (midX + radius * Math.cos(angleRadians));
float pointY = (float) (midY + radius * Math.sin(angleRadians));
arcPath.moveTo(startX, startY);
arcPath.cubicTo(startX,startY,pointX,pointY, endX, endY);
return arcPath;
}
示例7: getValue
import android.view.View; //导入方法依赖的package包/类
/**
* This method gets the value of the named property from the View object.
*
* @param propertyConstant The property whose value should be returned
* @return float The value of the named property
*/
private float getValue(int propertyConstant) {
//final View.TransformationInfo info = mView.mTransformationInfo;
View v = mView.get();
if (v != null) {
switch (propertyConstant) {
case TRANSLATION_X:
//return info.mTranslationX;
return v.getTranslationX();
case TRANSLATION_Y:
//return info.mTranslationY;
return v.getTranslationY();
case ROTATION:
//return info.mRotation;
return v.getRotation();
case ROTATION_X:
//return info.mRotationX;
return v.getRotationX();
case ROTATION_Y:
//return info.mRotationY;
return v.getRotationY();
case SCALE_X:
//return info.mScaleX;
return v.getScaleX();
case SCALE_Y:
//return info.mScaleY;
return v.getScaleY();
case X:
//return v.mLeft + info.mTranslationX;
return v.getX();
case Y:
//return v.mTop + info.mTranslationY;
return v.getY();
case ALPHA:
//return info.mAlpha;
return v.getAlpha();
}
}
return 0;
}
示例8: getTranslationX
import android.view.View; //导入方法依赖的package包/类
public static float getTranslationX(View view) {
if (View10.NEED_PROXY) {
return View10.wrap(view).getTranslationX();
} else {
return view.getTranslationX();
}
}
示例9: supportGetTranslationX
import android.view.View; //导入方法依赖的package包/类
private int supportGetTranslationX(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
return (int) v.getTranslationX();
}
return 0;
}
示例10: getLeft
import android.view.View; //导入方法依赖的package包/类
public static int getLeft(View v) {
if (MenuDrawer.USE_TRANSLATIONS) {
return (int) (v.getLeft() + v.getTranslationX());
}
return v.getLeft();
}
示例11: onDraw
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
View view = getChildAt(0);
float width = view.getWidth();
float height = view.getHeight();
int left1 = view.getLeft();
int top1 = view.getTop();
float w = left1+width / 2;
float h = top1+height / 2;
float x = left1 +view.getTranslationX()+ width / 2;
float y = top1 +view.getTranslationY()+ height / 2;
path.reset();
//移动点
canvas.drawCircle(x, y, RADIUS_MOVE, paint);
double sqrt = Math.sqrt((x - w) * (x - w) + (y - h) * (y - h));
if (sqrt >= DISTANCE || isLeave) {
doLeave();
return;
}
float p = (float) ((OUTLENGTH - sqrt) / OUTLENGTH);
float radius = ORGINLENGTH * p;
canvas.drawCircle(w, h, radius, paint);
// Log.i(TAG, "draw: " + sqrt);
double cose = (x - w) / sqrt;
double sine = (y - h) / sqrt;
double dy = RADIUS_MOVE * cose;
double dx = RADIUS_MOVE * sine;
double dy1 = radius * cose;
double dx1 = radius * sine;
float x1 = (float) (w - dx1);
float y1 = (float) (h + dy1);
float x4 = (float) (w + dx1);
float y4 = (float) (h - dy1);
float x2 = (float) (x - dx);
float y2 = (float) (y + dy);
float x3 = (float) (x + dx);
float y3 = (float) (y - dy);
float xx = w + (x - w) / 2;
float yy = h + (y - h) / 2;
path.moveTo(x1, y1);
path.quadTo(xx, yy, x2, y2);
path.lineTo(x3, y3);
path.quadTo(xx, yy, x4, y4);
path.close();
canvas.drawPath(path, paint);
// canvas.drawCircle(x1, y1, 15, paint1);
// canvas.drawCircle(x2, y2, 15, paint1);
// canvas.drawCircle(x3, y3, 15, paint2);
// canvas.drawCircle(x4, y4, 15, paint2);
// canvas.drawCircle(xx, yy, 15, paint2);
}
示例12: updateChildrenPosition
import android.view.View; //导入方法依赖的package包/类
private void updateChildrenPosition() {
updateTargetViewLocation();
for (View child : mChildren) {
if (mTargetLocation[0] == child.getTranslationX()
&& mTargetLocation[1] == child.getTranslationY())
break;
child.setTranslationX(mTargetLocation[0]);
child.setTranslationY(mTargetLocation[1]);
child.requestLayout();
}
}
示例13: getRight
import android.view.View; //导入方法依赖的package包/类
@SuppressLint("NewApi")
static int getRight(View v) {
return (int) (v.getRight() + v.getTranslationX());
}
示例14: getTranslationX
import android.view.View; //导入方法依赖的package包/类
public static float getTranslationX(View view) {
return view.getTranslationX();
}
示例15: getLeft
import android.view.View; //导入方法依赖的package包/类
@SuppressLint("NewApi")
static int getLeft(View v) {
return (int) (v.getLeft() + v.getTranslationX());
}