日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android闪闪发光字体

發布時間:2023/12/20 Android 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android闪闪发光字体 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如上圖所示閃閃發光字體:

HTextView 來源于?

implementation 'com.hanks:htextview-base:0.1.2'

public class RainbowTextView extends HTextView {private Matrix mMatrix; private float mTranslate; private float colorSpeed; private float colorSpace; private int[] colors = {0XFF13C0FD, 0XFF11B2F7, 0XFF0D9BEE, 0XFF0984E6, 0XFF0879E1}; private LinearGradient mLinearGradient; public RainbowTextView(Context context) {this(context, null); }public RainbowTextView(Context context, AttributeSet attrs) {this(context, attrs, 0); }public RainbowTextView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr); init(attrs, defStyleAttr); }@Override public void setAnimationListener(AnimationListener listener) {throw new UnsupportedOperationException("Invalid operation for rainbow"); }private void init(AttributeSet attrs, int defStyleAttr) {TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.RainbowTextView); colorSpace = typedArray.getDimension(R.styleable.RainbowTextView_colorSpace, DisplayUtils.dp2px(150)); colorSpeed = typedArray.getDimension(R.styleable.RainbowTextView_colorSpeed, DisplayUtils.dp2px(5)); typedArray.recycle(); mMatrix = new Matrix(); initPaint(); }public float getColorSpace() {return colorSpace; }public void setColorSpace(float colorSpace) {this.colorSpace = colorSpace; }public float getColorSpeed() {return colorSpeed; }public void setColorSpeed(float colorSpeed) {this.colorSpeed = colorSpeed; }public void setColors(int... colors) {this.colors = colors; initPaint(); }private void initPaint() {int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); measure(w, h); int height = getMeasuredHeight(); mLinearGradient = new LinearGradient(0, 0, 0, height, colors, new float[]{0, 0.25f, 0.5f, 0.75f, 1.0f}, Shader.TileMode.MIRROR); getPaint().setShader(mLinearGradient); }@Override public void setProgress(float progress) {}@Override public void animateText(CharSequence text) {setText(text); }@Override protected void onDraw(Canvas canvas) {if (mMatrix == null) {mMatrix = new Matrix(); }mTranslate += colorSpeed; mMatrix.setTranslate(0, mTranslate); mLinearGradient.setLocalMatrix(mMatrix); super.onDraw(canvas); postInvalidateDelayed(100); }

總結

以上是生活随笔為你收集整理的Android闪闪发光字体的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。