Java Code Examples for android.widget.TextView#setTranslationY()

The following examples show how to use android.widget.TextView#setTranslationY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupSettingsCoordinatorLayoutBehavior.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void updateNamePosition(@NonNull CoordinatorLayout parent, float factor) {
  TextView child  = (TextView) groupNameRef.require(parent);
  View     target = groupNameTargetRef.require(parent);

  targetRect.set(target.getLeft(), target.getTop(), target.getRight(), target.getBottom());
  childRect.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());

  if (child.getMaxWidth() != targetRect.width()) {
    child.setMaxWidth(targetRect.width());
  }

  float deltaTop   = targetRect.top - childRect.top;
  float deltaStart = getStart(parent, targetRect) - getStart(parent, childRect);

  float yTranslation = deltaTop * factor;
  float xTranslation = deltaStart * factor;

  child.setTranslationY(yTranslation);
  child.setTranslationX(xTranslation);
}
 
Example 2
Source File: ActivityAnimSegment.java    From PhotoMovie with Apache License 2.0 6 votes vote down vote up
@Override
public void drawFrame(Activity painter, float segmentProgress) {
    TextView textView = (TextView) painter.findViewById(android.R.id.content).findViewWithTag("text");
    textView.setRotation(segmentProgress * 7200);

    int maxX = (int) (mViewportRect.width() / 2);
    int maxY = (int) (mViewportRect.height() / 2);

    if (!(mTransX > -maxX && mTransX < maxX)) {
        mStepX = getRanStep();
        mStepX = mTransX > 0 ? -mStepX : mStepX;
    }
    mTransX += mStepX;

    if (!(mTransY > -maxY && mTransY < maxY)) {
        mStepY = getRanStep();
        mStepY = mTransY > 0 ? -mStepY : mStepY;
    }
    mTransY += mStepY;

    textView.setTranslationX(mTransX);
    textView.setTranslationY(mTransY);
}
 
Example 3
Source File: SampleHeaderBehavior.java    From BehaviorDemo with Apache License 2.0 6 votes vote down vote up
@Override
public void onNestedPreScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull TextView child, @NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) {
    super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
    if (target instanceof RecyclerView) {
        RecyclerView list = (RecyclerView) target;
        //列表第一个全部可见Item的位置
        int pos = ((LinearLayoutManager) list.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
        if (pos == 0 && pos < lastPosition) {
            downReach = true;
        }

        if (canScroll(child, dy) && pos == 0) {
            float finalY = child.getTranslationY() - dy;
            if (finalY < -child.getHeight()) {
                finalY = -child.getHeight();
                upReach = true;
            } else if (finalY > 0) {
                finalY = 0;
            }
            child.setTranslationY(finalY);
            consumed[1] = dy;
        }
        lastPosition = pos;
    }
}
 
Example 4
Source File: DonationActivity.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
private void showPromptText(TextView v) {
	if (currentPrompt == 2) {
		v.setText(getString(R.string.donation_prompt_three));
	} else if (currentPrompt == PAYMENT_STEP) {
		v.setText(getString(R.string.donation_prompt_four));
	} else if (currentPrompt > PAYMENT_STEP) {
		if (donationStep == 0) {
			v.setText(getString(R.string.donation_prompt_nothing));
		} else {
			v.setText(getString(R.string.donation_prompt_donated));
		}
	}


	Interpolator interpolator = new AccelerateDecelerateInterpolator();
	v.setTranslationY((v.getHeight()));
	v.animate().alpha(1f).translationY(0).setDuration(animationDuration).setInterpolator(interpolator).start();
}
 
Example 5
Source File: ViewPagerFragment.java    From beauty-treatment-android-animations with Apache License 2.0 6 votes vote down vote up
private void transformHeaderTextViews(float progress, int currentPage) {

        TextView textView = userDetailsTextViews[currentPage];
        float translationY;

        if (progress < -1) { // [-Infinity,-1)
            translationY = viewPagerHeaderHeight * 2;

        } else if (progress <= 1) { // (0,1]
            translationY = progress * -viewPagerHeaderHeight * 2;

        } else { // (1,+Infinity]
            translationY = -viewPagerHeaderHeight * 2;
        }

        textView.setTranslationY(translationY);
    }
 
Example 6
Source File: PopupTextView.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
public boolean popupText(String text) {
    final TextView tv = mFreePool.pop();
    if (tv == null) {
        return false;
    }

    tv.setTranslationY(0);
    tv.setAlpha(1.0f);
    tv.setVisibility(VISIBLE);
    tv.setText(text);

    // Start animate
    tv.animate().y(0.0f).alpha(0.0f).setDuration(1000)
            .setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR)
            .setListener(new SimpleAnimatorListener() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    tv.setVisibility(INVISIBLE);
                    mFreePool.push(tv);
                }
            }).start();
    return true;
}
 
Example 7
Source File: PasscodeView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (dotRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(dotRunnable);
        dotRunnable = null;
    }
    if (currentAnimation != null) {
        currentAnimation.cancel();
        currentAnimation = null;
    }

    for (int a = 0; a < 4; a++) {
        if (a < stringBuilder.length()) {
            TextView textView = characterTextViews.get(a);
            textView.setAlpha(0);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));

            textView = dotTextViews.get(a);
            textView.setAlpha(1);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));
        } else {
            characterTextViews.get(a).setAlpha(0);
            dotTextViews.get(a).setAlpha(0);
        }
    }
    super.onLayout(changed, left, top, right, bottom);
}
 
Example 8
Source File: PasscodeView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (dotRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(dotRunnable);
        dotRunnable = null;
    }
    if (currentAnimation != null) {
        currentAnimation.cancel();
        currentAnimation = null;
    }

    for (int a = 0; a < 4; a++) {
        if (a < stringBuilder.length()) {
            TextView textView = characterTextViews.get(a);
            textView.setAlpha(0);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));

            textView = dotTextViews.get(a);
            textView.setAlpha(1);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));
        } else {
            characterTextViews.get(a).setAlpha(0);
            dotTextViews.get(a).setAlpha(0);
        }
    }
    super.onLayout(changed, left, top, right, bottom);
}
 
Example 9
Source File: PasscodeView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (dotRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(dotRunnable);
        dotRunnable = null;
    }
    if (currentAnimation != null) {
        currentAnimation.cancel();
        currentAnimation = null;
    }

    for (int a = 0; a < 4; a++) {
        if (a < stringBuilder.length()) {
            TextView textView = characterTextViews.get(a);
            textView.setAlpha(0);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));

            textView = dotTextViews.get(a);
            textView.setAlpha(1);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));
        } else {
            characterTextViews.get(a).setAlpha(0);
            dotTextViews.get(a).setAlpha(0);
        }
    }
    super.onLayout(changed, left, top, right, bottom);
}
 
Example 10
Source File: LLand.java    From heads-up with GNU General Public License v3.0 5 votes vote down vote up
public void setScoreField(TextView tv) {
    mScoreField = tv;
    if (tv != null) {
        if (Build.VERSION.SDK_INT >= 21)
            tv.setTranslationZ(PARAMS.HUD_Z);
        if (!(mAnimating && mPlaying)) {
            tv.setTranslationY(-500);
        }
    }
}
 
Example 11
Source File: TitleChanger.java    From material-calendarview with MIT License 5 votes vote down vote up
private void doTranslation(final TextView title, final int translate) {
  if (orientation == MaterialCalendarView.HORIZONTAL) {
    title.setTranslationX(translate);
  } else {
    title.setTranslationY(translate);
  }
}
 
Example 12
Source File: FABMenu.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void updateFabTranslationForSnackbar(CoordinatorLayout parent,
                                             FloatingActionButton fab, View snackbar) {
    float translationY = this.getFabTranslationYForSnackbar(parent, fab);
    fab.setTranslationY(translationY);

    for (FloatingActionButton child : ((FABMenu) fab).children) {
        child.setTranslationY(translationY);
    }

    for (TextView label : ((FABMenu) fab).labels) {
        label.setTranslationY(translationY);
    }
}
 
Example 13
Source File: TitleChanger.java    From calendarview2 with MIT License 5 votes vote down vote up
private void doTranslation(final TextView title, final int translate) {
    if (orientation == CalendarView2.HORIZONTAL) {
        title.setTranslationX(translate);
    } else {
        title.setTranslationY(translate);
    }
}
 
Example 14
Source File: RxPopupViewManager.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
private void moveTipToCorrectPosition(TextView tipView, Point p) {
    RxCoordinates tipViewRxCoordinates = new RxCoordinates(tipView);
    int translationX = p.x - tipViewRxCoordinates.left;
    int translationY = p.y - tipViewRxCoordinates.top;
    if (!RxPopupViewTool.isRtl()) tipView.setTranslationX(translationX);
    else tipView.setTranslationX(-translationX);
    tipView.setTranslationY(translationY);
}
 
Example 15
Source File: PasscodeView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (dotRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(dotRunnable);
        dotRunnable = null;
    }
    if (currentAnimation != null) {
        currentAnimation.cancel();
        currentAnimation = null;
    }

    for (int a = 0; a < 4; a++) {
        if (a < stringBuilder.length()) {
            TextView textView = characterTextViews.get(a);
            textView.setAlpha(0);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));

            textView = dotTextViews.get(a);
            textView.setAlpha(1);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));
        } else {
            characterTextViews.get(a).setAlpha(0);
            dotTextViews.get(a).setAlpha(0);
        }
    }
    super.onLayout(changed, left, top, right, bottom);
}
 
Example 16
Source File: TitleChanger.java    From monthweekmaterialcalendarview with Apache License 2.0 5 votes vote down vote up
private void doTranslation(final TextView title, final int translate) {
    if (orientation == MaterialCalendarView.HORIZONTAL) {
        title.setTranslationX(translate);
    } else {
        title.setTranslationY(translate);
    }
}
 
Example 17
Source File: MainActivity.java    From ScrollableLayout with Apache License 2.0 4 votes vote down vote up
private void initView() {
    pfl_root = (PtrClassicFrameLayout) findViewById(R.id.pfl_root);
    sl_root = (ScrollableLayout) findViewById(R.id.sl_root);
    vp_scroll = (ViewPager) findViewById(R.id.vp_scroll);
    tv_title = (TextView) findViewById(R.id.tv_title);
    tv_right = (TextView) findViewById(R.id.tv_right);
    iv_spit = (ImageView) findViewById(R.id.iv_spit);
    tv_name = (TextView) findViewById(R.id.tv_name);
    tv_signature = (TextView) findViewById(R.id.tv_signature);
    iv_avatar = (ImageView) findViewById(R.id.iv_avatar);

    ly_page1 = (RelativeLayout) findViewById(R.id.ly_page1);
    tv_page1 = (TextView) findViewById(R.id.tv_page1);
    ly_page2 = (RelativeLayout) findViewById(R.id.ly_page2);
    tv_page2 = (TextView) findViewById(R.id.tv_page2);

    iv_spit.setVisibility(View.GONE);
    tv_title.setTranslationY(-1000);
    sl_root.setOnScrollListener(new ScrollableLayout.OnScrollListener() {
        @Override
        public void onScroll(int translationY, int maxY) {
            translationY = -translationY;
            if (titleMaxScrollHeight == 0) {
                titleMaxScrollHeight = ((View) tv_title.getParent()).getBottom() - tv_title.getTop();
                maxScrollHeight = hearderMaxHeight + titleMaxScrollHeight;
            }
            if (hearderMaxHeight == 0) {
                hearderMaxHeight = tv_name.getTop();
                maxScrollHeight = hearderMaxHeight + titleMaxScrollHeight;
            }
            if (avatarTop == 0) {
                avatarTop = iv_avatar.getTop();
            }

            int alpha = 0;
            int baseAlpha = 60;
            if (0 > avatarTop + translationY) {
                alpha = Math.min(255, (int) (Math.abs(avatarTop + translationY) * (255 - baseAlpha) / (hearderMaxHeight - avatarTop) + baseAlpha));
                iv_spit.setVisibility(View.VISIBLE);
            } else {
                iv_spit.setVisibility(View.GONE);
            }

            iv_spit.getBackground().setAlpha(alpha);

            tv_title.setTranslationY(Math.max(0, maxScrollHeight + translationY));
        }
    });

    pfl_root.setEnabledNextPtrAtOnce(true);
    pfl_root.setLastUpdateTimeRelateObject(this);
    pfl_root.setPtrHandler(this);
    pfl_root.setKeepHeaderWhenRefresh(true);

    CommonFragementPagerAdapter commonFragementPagerAdapter = new CommonFragementPagerAdapter(getSupportFragmentManager());
    fragmentList.add(RecyclerViewSimpleFragment.newInstance());
    fragmentList.add(RecyclerViewGridSimpleFragment.newInstance());
    vp_scroll.setAdapter(commonFragementPagerAdapter);
    vp_scroll.addOnPageChangeListener(this);
    sl_root.getHelper().setCurrentScrollableContainer(fragmentList.get(0));

    tv_right.setOnClickListener(this);
    tv_signature.setOnClickListener(this);
    ly_page1.setOnClickListener(this);
    ly_page2.setOnClickListener(this);
}
 
Example 18
Source File: TestFloatingBehavior.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {
  child.setTranslationY(Math.min(0, dependency.getTranslationY() - dependency.getHeight()));
  return true;
}