android.widget.TextView#setTranslationY ( )源码实例Demo

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

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);
}
 
源代码2 项目: PhotoMovie   文件: ActivityAnimSegment.java
@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);
}
 
源代码3 项目: BehaviorDemo   文件: SampleHeaderBehavior.java
@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;
    }
}
 
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();
}
 
源代码5 项目: Nimingban   文件: PopupTextView.java
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;
}
 
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);
    }
 
源代码7 项目: TelePlus-Android   文件: PasscodeView.java
@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);
}
 
private void doTranslation(final TextView title, final int translate) {
    if (orientation == MaterialCalendarView.HORIZONTAL) {
        title.setTranslationX(translate);
    } else {
        title.setTranslationY(translate);
    }
}
 
源代码9 项目: TelePlus-Android   文件: PasscodeView.java
@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);
}
 
源代码10 项目: RxTools-master   文件: RxPopupViewManager.java
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);
}
 
源代码11 项目: calendarview2   文件: TitleChanger.java
private void doTranslation(final TextView title, final int translate) {
    if (orientation == CalendarView2.HORIZONTAL) {
        title.setTranslationX(translate);
    } else {
        title.setTranslationY(translate);
    }
}
 
源代码12 项目: Jockey   文件: FABMenu.java
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);
    }
}
 
源代码13 项目: material-calendarview   文件: TitleChanger.java
private void doTranslation(final TextView title, final int translate) {
  if (orientation == MaterialCalendarView.HORIZONTAL) {
    title.setTranslationX(translate);
  } else {
    title.setTranslationY(translate);
  }
}
 
源代码14 项目: heads-up   文件: LLand.java
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);
        }
    }
}
 
源代码15 项目: Telegram-FOSS   文件: PasscodeView.java
@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);
}
 
源代码16 项目: Telegram   文件: PasscodeView.java
@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);
}
 
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {
  child.setTranslationY(Math.min(0, dependency.getTranslationY() - dependency.getHeight()));
  return true;
}
 
源代码18 项目: ScrollableLayout   文件: MainActivity.java
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);
}
 
 方法所在类
 同类方法