Esempio n. 1
1
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   int widthmode = MeasureSpec.getMode(widthMeasureSpec);
   int widthsize = MeasureSpec.getSize(widthMeasureSpec);
   int heightmode = MeasureSpec.getMode(heightMeasureSpec);
   int heightsize = MeasureSpec.getSize(heightMeasureSpec);
   if (widthmode == MeasureSpec.AT_MOST && heightmode == MeasureSpec.AT_MOST) {
     setMeasuredDimension(
         (int) mTextSize * text.length() + getPaddingLeft() + getPaddingRight(),
         (int) mTextSize
             + getPaddingTop()
             + getPaddingBottom()
             + DensityUtil.px2dip(mContext, 300));
   } else if (widthmode == MeasureSpec.AT_MOST) {
     setMeasuredDimension(
         (int) mTextSize * text.length() + getPaddingLeft() + getPaddingRight(), heightsize);
   } else if (heightmode == MeasureSpec.AT_MOST) {
     setMeasuredDimension(
         widthsize,
         (int) mTextSize
             + getPaddingTop()
             + getPaddingBottom()
             + DensityUtil.px2dip(mContext, 300));
   }
 }
Esempio n. 2
0
  private void PlayAnimator() {
    if (i < text.length()) {
      mPath.moveTo(0, 0); // 起点
      mPath.quadTo(
          (mTextSize * i) / 2, 0, mTextSize * i, mTextSize + DensityUtil.px2dip(mContext, 300));
      mPathMeasure = new PathMeasure(mPath, false);
      animator = ValueAnimator.ofFloat(0, mPathMeasure.getLength());
      animator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              float value = (Float) animation.getAnimatedValue();
              mPathMeasure.getPosTan(value, mCurrentPosition, null);
              postInvalidate();
            }
          });
      mPath.close();
      animator.setDuration(1500);
      animator.setRepeatMode(ValueAnimator.RESTART);
      animator.setInterpolator(new LinearInterpolator());
      animator.start();
      animator.addListener(
          new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {}

            @Override
            public void onAnimationEnd(Animator animator) {
              // 每一个动画执行完成后记录最后一个坐标点
              Point point = new Point();
              point.x = (int) mCurrentPosition[0];
              point.y = (int) mCurrentPosition[1];
              endloc.put(i, point);
              i++;
              if (i >= text.length()) { // 当i大于7的时候置为零方便下次循环
                i = 0;
                endloc.clear(); // 清空集合,从新来过
              }
              mPath.reset();
              PlayAnimator();
            }

            @Override
            public void onAnimationCancel(Animator animator) {}

            @Override
            public void onAnimationRepeat(Animator animator) {}
          });
    }
  }
Esempio n. 3
0
 public ParabolicTextView(Context context, AttributeSet attrs, int defStyleAttr) {
   super(context, attrs, defStyleAttr);
   mContext = context.getApplicationContext();
   TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.JumpTextView);
   color = typedArray.getColor(R.styleable.JumpTextView_textColor, Color.BLACK);
   text = typedArray.getString(R.styleable.JumpTextView_text);
   if (text == null) {
     text = "Hello word";
   }
   mTextSize = typedArray.getFloat(R.styleable.JumpTextView_textSize, 40);
   mTextSize = DensityUtil.px2dip(mContext, mTextSize);
   typedArray.recycle();
   init();
 }