android+字体+动画效果怎么做的,Android自定义View实现闪耀字体效果

本文实例为大家分享了闪耀字体效果的具体代码,供大家参考,具体内容如下

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.LinearGradient;

import android.graphics.Matrix;

import android.graphics.Paint;

import android.graphics.Shader;

import android.util.AttributeSet;

import android.widget.TextView;

/**

* 闪耀字体

*/

public class ShiningFontView extends TextView {

private int mViewWidth;

private Paint mPaint;

private LinearGradient mLinearGradient;

private Matrix mGradientMatrix;

private int mTranslate;

public ShiningFontView(Context context) {

super(context);

}

public ShiningFontView(Context context,AttributeSet attrs) {

super(context,attrs);

}

public ShiningFontView(Context context,AttributeSet attrs,int defStyleAttr) {

super(context,attrs,defStyleAttr);

}

@Override

protected void onSizeChanged(int w,int h,int oldw,int oldh) {

super.onSizeChanged(w,h,oldw,oldh);

if (mViewWidth == 0) {

mViewWidth = getMeasuredWidth();

if (mViewWidth > 0) {

mPaint = getPaint();

mLinearGradient = new LinearGradient(0,mViewWidth,new int[]{Color.BLUE,0xffffffff,Color.BLUE},null,Shader.TileMode.CLAMP);

mPaint.setShader(mLinearGradient);

mGradientMatrix = new Matrix();

}

}

}

@Override

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

if (mGradientMatrix != null) {

mTranslate += mViewWidth / 5;

if (mTranslate > 2 * mViewWidth) {

mTranslate = -mViewWidth;

}

mGradientMatrix.setTranslate(mTranslate,0);

mLinearGradient.setLocalMatrix(mGradientMatrix);

postInvalidateDelayed(100);

}

}

}

使用方式如下

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:layout_marginLeft="@dimen/margin_10"

android:layout_toRightOf="@id/iv_tips1_icon"

android:text="@string/tips1" />

效果图如下

15059066451.jpg?201709153945

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

小编个人微信号 jb51ccc

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值