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

The following are Jave code examples for showing how to use getTranslationY() 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: AcademApp   File: MaterialIn.java   Source Code and License Vote up 6 votes
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();
    }
}
 
Example 2
Project: GitHub   File: FloatLayoutHelper.java   Source Code and License Vote up 6 votes
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();
}
 
Example 3
Project: CoordinatorLayoutExample-master   File: UcNewsHeaderPagerBehavior.java   Source Code and License Vote up 6 votes
private void handleActionUp(CoordinatorLayout parent, final View child) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "handleActionUp: ");
    }
    if (mFlingRunnable != null) {
        child.removeCallbacks(mFlingRunnable);
        mFlingRunnable = null;
    }
    mFlingRunnable = new FlingRunnable(parent, child);
    if (child.getTranslationY() < getHeaderOffsetRange() / 3.0f) {
        mFlingRunnable.scrollToClosed(DURATION_SHORT);
    } else {
        mFlingRunnable.scrollToOpen(DURATION_SHORT);
    }

}
 
Example 4
Project: Tangram-Android   File: SwipeItemTouchListener.java   Source Code and License Vote up 6 votes
private View findScrollableChildViewUnder(MotionEvent event) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final int first = getLayoutManager().findFirstVisibleItemPosition();
    final int last = getLayoutManager().findLastVisibleItemPosition();
    for (int i = 0; i <= last - first; i++) {
        View child = getLayoutManager().getChildAt(i);
        if (child instanceof ViewGroup) {
            float translationX = child.getTranslationX();
            float translationY = child.getTranslationY();
            if (x >= (float) child.getLeft() + translationX
                && x <= (float) child.getRight() + translationX
                && y >= (float) child.getTop() + translationY
                && y <= (float) child.getBottom() + translationY) {
                if (findCanScrollView(child) != null) {
                    return child;
                }
            }
        }
    }
    return null;
}
 
Example 5
Project: boohee_v5.6   File: ViewPropertyAnimatorHC.java   Source Code and License Vote up 6 votes
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;
}
 
Example 6
Project: ucar-weex-core   File: StickyHeaderHelper.java   Source Code and License Vote up 6 votes
/**
 * Bring component with bigest pos to Front
 */
private void showSticky() {
  if(mCurrentStickyRef==null){
    WXLogUtils.e("Current Sticky ref is null.");
    return;
  }

  WXCell headComponent = mHeaderComps.get(mCurrentStickyRef);
  final View headerView = headComponent.getRealView();
  if (headerView == null) {
    WXLogUtils.e("Sticky header's real view is null.");
    return;
  }
  View header = mHeaderViews.get(headComponent.getRef());
  if( header != null){
    //already there
    header.bringToFront();
  }else {
    mHeaderViews.put(headComponent.getRef(), headerView);
    //record translation, it should not change after transformation
    final float translationX = headerView.getTranslationX();
    final float translationY = headerView.getTranslationY();
    headComponent.removeSticky();

    ViewGroup existedParent;
    if ((existedParent = (ViewGroup) headerView.getParent()) != null) {
      existedParent.removeView(headerView);
    }
    mParent.addView(headerView);
    //recover translation, sometimes it will be changed on fling
    headerView.setTranslationX(translationX);
    headerView.setTranslationY(translationY);

  }
  if (headComponent.getDomObject().getEvents().contains("sticky")) {
    headComponent.fireEvent("sticky");
  }
}
 
Example 7
Project: BestPracticeApp   File: SwipeCardLayout.java   Source Code and License Vote up 5 votes
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        Log.i(TAG, "onDraw: " + x + " " + y);
        float width = getWidth() / 2.0f;
        float height = getHeight() / 2.0f;
        View childAt = getChildAt(0);


        //画固定底片

        if (adapter.tQueue.size() > 1) {
            float s_width1 = childAt.getWidth() * mScale;
            float s_height1 = childAt.getHeight() * mScale;
            float dx1 = (s_width1 - s_width1 * mScale) / 2;
            float l1 = width - s_width1 / 2 + dx1;
            float t1 = height + s_height1 / 2 + mTranslate;
            float r1 = width + s_width1 / 2 - dx1;
            float b1 = t1 + mDy;

            rect.left = l1;
            rect.top = t1 - 20 * density;
            rect.right = r1;
            rect.bottom = b1;
            canvas.drawRoundRect(rect, round, round, paint);
            canvas.drawRoundRect(rect, round, round, paint_s);
        }


        if (adapter.tQueue.size() > 0) {
            float scaleX = childAt.getScaleX();
            float s_width = childAt.getWidth() * scaleX;
            float s_height = childAt.getHeight() * scaleX;

            float dx = (s_width - s_width * mScale) / 2;
            float l = width - s_width / 2 + dx;
            float t = height + s_height / 2 + childAt.getTranslationY();
            float r = width + s_width / 2 - dx;
            float b = t + mDy;

            rect.left = l;
            rect.top = t - 20 * density;
            rect.right = r;
            rect.bottom = b;
            canvas.drawRoundRect(rect, round, round, paint);
            canvas.drawRoundRect(rect, round, round, paint_s);
        }

    }
 
Example 8
Project: Cybernet-VPN   File: ElasticDrawer.java   Source Code and License Vote up 5 votes
private int supportGetTranslationY(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return (int) v.getTranslationY();
    }

    return 0;
}
 
Example 9
Project: PlusGram   File: ViewProxy.java   Source Code and License Vote up 5 votes
public static float getTranslationY(View view) {
    if (View10.NEED_PROXY) {
        return View10.wrap(view).getTranslationY();
    } else {
        return view.getTranslationY();
    }
}
 
Example 10
Project: BehaviorDemo   File: XiamiCommentBehavior.java   Source Code and License Vote up 5 votes
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    float commentScrollY = dependency.getTranslationY() / getHeaderOffset() * (dependency.getHeight() - getTitleHeight());
    float y = dependency.getHeight() - commentScrollY;
    child.setY(y);
    return true;
}
 
Example 11
Project: ultrasonic   File: DraggableDrawer.java   Source Code and License Vote up 5 votes
private int supportGetTranslationY(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return (int) v.getTranslationY();
    }

    return 0;
}
 
Example 12
Project: ultrasonic   File: ViewHelper.java   Source Code and License Vote up 5 votes
public static int getBottom(View v) {
    if (MenuDrawer.USE_TRANSLATIONS) {
        return (int) (v.getBottom() + v.getTranslationY());
    }

    return v.getBottom();
}
 
Example 13
Project: LuaViewPlayground   File: UDView.java   Source Code and License Vote up 5 votes
/**
 * 获取TranslationY
 *
 * @return
 */
public float getTranslationY() {
    final View view = getView();
    if (view != null) {
        return view.getTranslationY();
    }
    return 0;
}
 
Example 14
Project: RNLearn_Project1   File: PositionAndSizeAnimation.java   Source Code and License Vote up 5 votes
public PositionAndSizeAnimation(View view, int x, int y, int width, int height) {
  mView = view;

  mStartX = view.getX() - view.getTranslationX();
  mStartY = view.getY() - view.getTranslationY();
  mStartWidth = view.getWidth();
  mStartHeight = view.getHeight();

  mDeltaX = x - mStartX;
  mDeltaY = y - mStartY;
  mDeltaWidth = width - mStartWidth;
  mDeltaHeight = height - mStartHeight;
}
 
Example 15
Project: UcMainPagerDemo-master   File: UcNewsTitleBehavior.java   Source Code and License Vote up 5 votes
private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
    int headerOffsetRange = getHeaderOffsetRange();
    int titleOffsetRange = getTitleHeight();
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "offsetChildAsNeeded:" + dependency.getTranslationY());
    }
    if (dependency.getTranslationY() == headerOffsetRange) {
        child.setTranslationY(titleOffsetRange);
    } else if (dependency.getTranslationY() == 0) {
        child.setTranslationY(0);
    } else {
        child.setTranslationY((int) (dependency.getTranslationY() / (headerOffsetRange * 1.0f) * titleOffsetRange));
    }

}
 
Example 16
Project: CoordinatorLayoutExample-master   File: UcNewsTitleBehavior.java   Source Code and License Vote up 5 votes
private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
    int headerOffsetRange = getHeaderOffsetRange();
    int titleOffsetRange = getTitleHeight();
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "offsetChildAsNeeded:" + dependency.getTranslationY());
    }
    if (dependency.getTranslationY() == headerOffsetRange) {
        child.setTranslationY(titleOffsetRange);
    } else if (dependency.getTranslationY() == 0) {
        child.setTranslationY(0);
    } else {
        child.setTranslationY((int) (dependency.getTranslationY() / (headerOffsetRange * 1.0f) * titleOffsetRange));
    }

}
 
Example 17
Project: genius-groupie   File: DebugItemDecoration.java   Source Code and License Vote up 4 votes
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (!(prefs.getShowBounds() || prefs.getShowOffsets())) return;

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);

        RecyclerView.LayoutManager lm = parent.getLayoutManager();
        decoratedLeft = lm.getDecoratedLeft(child) + (int) child.getTranslationX();
        decoratedTop = lm.getDecoratedTop(child) + (int) child.getTranslationY();
        decoratedRight = lm.getDecoratedRight(child) + (int) child.getTranslationX();
        decoratedBottom = lm.getDecoratedBottom(child) + (int) child.getTranslationY();

        left = child.getLeft() + (int) child.getTranslationX();
        top = child.getTop() + (int) child.getTranslationY();
        right = child.getRight() + (int) child.getTranslationX();
        bottom = child.getBottom() + (int) child.getTranslationY();

        if (prefs.getShowBounds()) {
            paint.setColor(Color.RED);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(1);
            c.drawRect(decoratedLeft, decoratedTop, decoratedRight, decoratedBottom, paint);
        }

        if (prefs.getShowOffsets()) {
            paint.setStyle(Paint.Style.FILL);

            paint.setColor(leftColor);
            c.drawRect(decoratedLeft, decoratedTop, left, decoratedBottom, paint);

            paint.setColor(topColor);
            c.drawRect(decoratedLeft, decoratedTop, decoratedRight, top, paint);

            paint.setColor(rightColor);
            c.drawRect(right, decoratedTop, decoratedRight, decoratedBottom, paint);

            paint.setColor(bottomColor);
            c.drawRect(decoratedLeft, bottom, decoratedRight, decoratedBottom, paint);
        }
    }
}
 
Example 18
Project: LuaViewPlayground   File: ViewHelper.java   Source Code and License Vote up 4 votes
static float getTranslationY(View view) {
    return view.getTranslationY();
}
 
Example 19
Project: boohee_v5.6   File: ViewHelper.java   Source Code and License Vote up 4 votes
static float getTranslationY(View view) {
    return view.getTranslationY();
}
 
Example 20
Project: boohee_v5.6   File: ViewCompatHC.java   Source Code and License Vote up 4 votes
private static void tickleInvalidationFlag(View view) {
    float y = view.getTranslationY();
    view.setTranslationY(1.0f + y);
    view.setTranslationY(y);
}