SuperTextView 充电效果

2020-08-04  本文已影响0人  proud2008

https://gitee.com/aceyun/SuperTextView
implementation 'com.github.chenBingX:SuperTextView:3.2.5.64'

/*
 * Copyright (C) 2017 CoorChice <icechen_@outlook.com>
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 * <p>
 * Last modified 17-4-17 下午3:23
 */

package com.xin.view.supertext;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;

import com.coorchice.library.SuperTextView;
import com.hrg.hefei.R;

/**
 * Project Name:SuperTextView
 * 充电不停向上的动画效果 参考demo中的MoveEffectAdjuster
 * Notes:
 */

public class ChargeEffectAdjuster extends SuperTextView.Adjuster {

    private float heightTemp = 0;
    private Paint paint;
    private Path firstLinePath = new Path();
    private float density;


    @Override
    public void adjust(SuperTextView v, Canvas canvas) {
        int width = v.getWidth();
        int height = v.getHeight();
        if (density == 0) {
            density = v.getResources().getDisplayMetrics().density;
        }
        if (heightTemp <= 0 || heightTemp >= height) {
            heightTemp = height;
        }
        double velocity = 0.2 * density; /*控制动画的速度*/
        heightTemp = ((float) (heightTemp - velocity));
        firstLinePath.reset();
        firstLinePath.moveTo(0, height);
        firstLinePath.lineTo(width, height);
        firstLinePath.lineTo(width, heightTemp);
        firstLinePath.lineTo(0, heightTemp);
        firstLinePath.close();
        if (paint == null) {
            paint = new Paint();
            paint.setAntiAlias(true);
            paint.setDither(true);
            paint.setColor(v.getResources().getColor(R.color.red_gys_));
            paint.setStyle(Paint.Style.FILL);
        }
        canvas.drawPath(firstLinePath, paint);

    }
}

上一篇下一篇

猜你喜欢

热点阅读