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

The following are Jave code examples for showing how to use setTranslationY() 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: ArcLayout-master   File: MainActivity.java   Source Code and License Vote up 8 votes
private Animator createShowItemAnimator(View item) {

        float dx = fab.getX() - item.getX();
        float dy = fab.getY() - item.getY();

        item.setRotation(0f);
        item.setTranslationX(dx);
        item.setTranslationY(dy);

        Animator anim = ObjectAnimator.ofPropertyValuesHolder(
                item,
//                AnimatorUtils.rotation(0f, 720f),
                AnimatorUtils.translationX(dx, 0f),
                AnimatorUtils.translationY(dy, 0f)
        );

        return anim;
    }
 
Example 2
Project: UcMainPagerDemo-master   File: UcNewsTabBehavior.java   Source Code and License Vote up 6 votes
private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
    float offsetRange = dependency.getTop() + getFinalHeight() - child.getTop();
    int headerOffsetRange = getHeaderOffsetRange();
    if (dependency.getTranslationY() == headerOffsetRange) {
        child.setTranslationY(offsetRange);
    } else if (dependency.getTranslationY() == 0) {
        child.setTranslationY(0);
    } else {
        child.setTranslationY((int) (dependency.getTranslationY() / (getHeaderOffsetRange() * 1.0f) * offsetRange));
    }
}
 
Example 3
Project: spruce-android   File: VerticalViewPager.java   Source Code and License Vote up 6 votes
@Override
public void transformPage(View view, float position) {

    if (position < -1) {
        view.setAlpha(0);

    } else if (position <= 1) {
        view.setAlpha(1);

        view.setTranslationX(view.getWidth() * -position);

        float yPosition = position * view.getHeight();
        view.setTranslationY(yPosition);

    } else {
        view.setAlpha(0);
    }
}
 
Example 4
Project: garras   File: PageAnimator.java   Source Code and License Vote up 6 votes
protected void transformUnderlyingPage(View page, float position, boolean enter) {
    page.setAlpha(1);
    page.setScaleX(1);
    page.setScaleY(1);
    page.setTranslationX(0);
    page.setTranslationY(0);
    // Avoid overdraw
    page.setVisibility(View.INVISIBLE);
}
 
Example 5
Project: Farmacias   File: FindRecyclerViewAdapter.java   Source Code and License Vote up 6 votes
private void runEnterAnimation(View view, int position) {
    if (position >= ANIMATED_ITEMS_COUNT - 1) {
        return;
    }


    if (scrollDirection == Constants.SCROLL_UP) {
        Log.d(LOG_TAG, "runEnterAnimation_up");
        if (position > lastAnimatedPosition) {
            lastAnimatedPosition = position;
            Log.d(LOG_TAG, "lasAnimated,position" + lastAnimatedPosition + "," + position);
            view.setTranslationY(Utils.getScreenHeight(mContext));
            ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(view,"translationY",0);
            objectAnimator.setDuration(700)
                    .setInterpolator(new DecelerateInterpolator(3.f));
            objectAnimator.start();
        }
    } else {
        Log.d(LOG_TAG, "runEnterAnimation_down");
        if (position < lastAnimatedPosition) {
            Log.d(LOG_TAG, "lasAnimated,position" + lastAnimatedPosition + "," + position);
            lastAnimatedPosition = position;

        }
    }
}
 
Example 6
Project: PageScrollView   File: TestPageTransformer.java   Source Code and License Vote up 6 votes
public void transformPage(View view, float position, boolean horizontal) {
    int pageSize = horizontal ? view.getWidth() : view.getHeight();
    if (position < -1) { // [-Infinity,-1)way off-screen to the left
        view.setAlpha(MIN_ALPHA);
        view.setScaleX(MIN_SCALE);
        view.setScaleY(MIN_SCALE);
    } else if (position <= 1) { // [-1,1]
        float percent = 1 - Math.abs(position);
        float scale = MIN_SCALE + (1 - MIN_SCALE) * percent;
        if (mAdjustTranslate) {
            float horizontalMargin = pageSize * (1 - scale) / 2;
            if (position > 0) {
                if (horizontal) {
                    view.setTranslationX(horizontalMargin);
                } else {
                    view.setTranslationY(horizontalMargin);
                }
            } else {
                if (horizontal) {
                    view.setTranslationX(-horizontalMargin);
                } else {
                    view.setTranslationY(-horizontalMargin);
                }
            }
        }
        view.setScaleX(scale);
        view.setScaleY(scale);
        view.setAlpha(MIN_ALPHA + (1 - MIN_ALPHA) * percent);
    } else { // (1,+Infinity]page is way off-screen to the right.
        view.setAlpha(MIN_ALPHA);
        view.setScaleX(MIN_SCALE);
        view.setScaleY(MIN_SCALE);
    }
}
 
Example 7
Project: VerticalViewPager   File: DefaultTransformer.java   Source Code and License Vote up 5 votes
@Override
public void transformPage(View view, float position) {
    float alpha = 0;
    if (0 <= position && position <= 1) {
        alpha = 1 - position;
    } else if (-1 < position && position < 0) {
        alpha = position + 1;
    }
    view.setAlpha(alpha);
    view.setTranslationX(view.getWidth() * -position);
    float yPosition = position * view.getHeight();
    view.setTranslationY(yPosition);
}
 
Example 8
Project: InstaFlickr   File: FeedAdapter.java   Source Code and License Vote up 5 votes
private void runEnterAnimation(View view, int position) {
    if(position >= ANIMATED_ITEMS_COUNT - 1){//加载的item数大于等于屏幕所能装下的item数则动画加载完成(第一次加载前两个item采用动画效果)
        return;
    }
    if(position > lastAnimatedPosition){//lastAnimatedPosition初始值为-1,随position增加不断更新最后一个position的值
        lastAnimatedPosition = position;
        view.setTranslationY(Utils.getScreenHeight(mContext));//起始的Y点坐标为屏幕最下方
        view.animate()
                .translationY(0)
                .setInterpolator(new DecelerateInterpolator(3.f))
                .setDuration(700)
                .start();
    }
}
 
Example 9
Project: stynico   File: Instrument.java   Source Code and License Vote up 5 votes
public void slidingByDelta(View view ,float delta){
    if(view == null){
        return;
    }
    view.clearAnimation();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setTranslationY(delta);
    }else{
       // ViewHelper.setTranslationY(view, delta);
    }
}
 
Example 10
Project: fragmentnav   File: Androids.java   Source Code and License Vote up 5 votes
public static void resetViewProperty(View view) {
    view.setScaleX(1.0f);
    view.setScaleY(1.0f);
    view.setAlpha(1.0f);
    view.setTranslationX(0);
    view.setTranslationY(0);
    view.setRotation(0);
    view.setRotationX(0);
    view.setRotationY(0);
    view.animate().setStartDelay(0).setListener(null);
}
 
Example 11
Project: UcMainPagerDemo-master   File: UcNewsHeaderPagerBehavior.java   Source Code and License Vote up 5 votes
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) {
    super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
    //dy>0 scroll up;dy<0,scroll down
    float halfOfDis = dy / 4.0f;
    if (!canScroll(child, halfOfDis)) {
        child.setTranslationY(halfOfDis > 0 ? getHeaderOffsetRange() : 0);
    } else {
        child.setTranslationY(child.getTranslationY() - halfOfDis);
    }
    //consumed all scroll behavior after we started Nested Scrolling
    consumed[1] = dy;
}
 
Example 12
Project: chromium-for-android-56-debug-video   File: ChromeFullscreenManager.java   Source Code and License Vote up 5 votes
private void applyTranslationToTopChildViews(ViewGroup contentView, float translation) {
    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            child.setTranslationY(translation);
            TraceEvent.instant("FullscreenManager:child.setTranslationY()");
        }
    }
}
 
Example 13
Project: android-project-gallery   File: ViewPropertyAnimatorHC.java   Source Code and License Vote up 5 votes
/**
 * This method handles setting the property values directly in the View object's fields.
 * propertyConstant tells it which property should be set, value is the value to set
 * the property to.
 *
 * @param propertyConstant The property to be set
 * @param value The value to set the property to
 */
private void setValue(int propertyConstant, float value) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //info.mTranslationX = value;
                v.setTranslationX(value);
                break;
            case TRANSLATION_Y:
                //info.mTranslationY = value;
                v.setTranslationY(value);
                break;
            case ROTATION:
                //info.mRotation = value;
                v.setRotation(value);
                break;
            case ROTATION_X:
                //info.mRotationX = value;
                v.setRotationX(value);
                break;
            case ROTATION_Y:
                //info.mRotationY = value;
                v.setRotationY(value);
                break;
            case SCALE_X:
                //info.mScaleX = value;
                v.setScaleX(value);
                break;
            case SCALE_Y:
                //info.mScaleY = value;
                v.setScaleY(value);
                break;
            case X:
                //info.mTranslationX = value - v.mLeft;
                v.setX(value);
                break;
            case Y:
                //info.mTranslationY = value - v.mTop;
                v.setY(value);
                break;
            case ALPHA:
                //info.mAlpha = value;
                v.setAlpha(value);
                break;
        }
    }
}
 
Example 14
Project: letv   File: ViewCompatHC.java   Source Code and License Vote up 4 votes
public static void setTranslationY(View view, float value) {
    view.setTranslationY(value);
}
 
Example 15
Project: VerticalViewPager   File: StackTransformer.java   Source Code and License Vote up 4 votes
@Override
public void transformPage(View page, float position) {
    page.setTranslationX(page.getWidth() * -position);
    page.setTranslationY(position < 0 ? position * page.getHeight() : 0f);
}
 
Example 16
Project: SlidingRootNav   File: YTranslationTransformation.java   Source Code and License Vote up 4 votes
@Override
public void transform(float dragProgress, View rootView) {
    float translation = SideNavUtils.evaluate(dragProgress, START_TRANSLATION, endTranslation);
    rootView.setTranslationY(translation);
}
 
Example 17
Project: Huahui-Android   File: MorphFabToDialog.java   Source Code and License Vote up 4 votes
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) {
    Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (startValues == null || endValues == null || changeBounds == null) {
        return null;
    }

    Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR);
    Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS);
    Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR);
    Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS);

    if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) {
        return null;
    }

    MorphDrawable background = new MorphDrawable(startColor, startCornerRadius);
    endValues.view.setBackground(background);

    Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
    Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);

    // ease in the dialog's child views (slide up & fade in)
    if (endValues.view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) endValues.view;
        float offset = vg.getHeight() / 3;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.setTranslationY(offset);
            v.setAlpha(0f);
            v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150)
                    .setInterpolator(AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in))
                    .start();
            offset *= 1.8f;
        }
    }

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, corners, color);
    transition.setDuration(300);
    transition.setInterpolator(AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    return transition;
}
 
Example 18
Project: Mybilibili   File: FooterBehaviorAppBar.java   Source Code and License Vote up 4 votes
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    float translationY = Math.abs(dependency.getY());
    child.setTranslationY(translationY);
    return true;
}
 
Example 19
Project: GitHub   File: WoWoTranslationAnimation.java   Source Code and License Vote up 4 votes
@Override
protected void toMiddleState(View view, float offset) {
    view.setTranslationX(fromX + (toX - fromX) * offset);
    view.setTranslationY(fromY + (toY - fromY) * offset);
}
 
Example 20
Project: UcMainPagerDemo-master   File: UcNewsContentBehavior.java   Source Code and License Vote up 2 votes
private void offsetChildAsNeeded(CoordinatorLayout parent, View child, View dependency) {
    child.setTranslationY((int) (-dependency.getTranslationY() / (getHeaderOffsetRange() * 1.0f) * getScrollRange(dependency)));

}