Android Textview实现颜色渐变滚动效果
作者:qq_29703975 时间:2023-08-28 05:30:08
本文实例为大家分享了Android颜色渐变滚动展示的具体代码,供大家参考,具体内容如下
public class FlashTextView extends android.support.v7.widget.AppCompatTextView {
private Paint mPaint;
private int mViewWidth;
private LinearGradient mLinearGradient;
private Matrix mGradientMatrix;
private int mTransalte;
public FlashTextView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@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();//获得当前绘制的Paint对象
mLinearGradient = new LinearGradient(
0,//渐变起始点x坐标
0,//渐变起始点y坐标
mViewWidth,//渐变结束点x点坐标
0,//渐变结束点y坐标
new int[]{
Color.BLUE, 0xffffffff,
Color.BLUE,Color.RED,Color.YELLOW},//颜色的int数组
null,//相对位置的颜色数组,可为null, 若为null,可为null,颜色沿渐变线均匀分布
Shader.TileMode.MIRROR);//平铺模式
mPaint.setShader(mLinearGradient);//给这个paint设置linearFradient属性
mGradientMatrix = new Matrix();
}
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mGradientMatrix != null) {
mTransalte += mViewWidth / 5;
if (mTransalte > 2 * mViewWidth) {
mTransalte -= mViewWidth;
}
mGradientMatrix.setTranslate(mTransalte, 0);
mLinearGradient.setLocalMatrix(mGradientMatrix);//通过矩阵的方式不断平移产生渐变效果
postInvalidateDelayed(100);
}
}
}
来源:http://blog.csdn.net/qq_29703975/article/details/66973941
标签:Android,Textview,渐变
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c# 如何将字符串转换为大写或小写
2023-01-04 20:44:28
![](https://img.aspxhome.com/file/2023/8/108818_0s.png)
sprng和struts有什么区别?
2022-03-02 02:13:35
Android 代码写控件代替XML简单实例
2023-04-11 00:10:48
Unity实现聊天室功能
2023-12-20 19:53:34
![](https://img.aspxhome.com/file/2023/2/119542_0s.jpg)
Android-App增量更新的使用姿势
2022-09-22 22:47:38
![](https://img.aspxhome.com/file/2023/7/139137_0s.jpg)
Android Fragment+FragmentTabHost组件实现常见主页面(仿微信新浪)
2023-10-20 10:00:50
SpringMVC上传和解析Excel方法
2022-02-23 21:02:11
![](https://img.aspxhome.com/file/2023/0/116170_0s.jpg)
安卓逆向腾讯动漫app返回数据加密分析案例分享
2023-10-24 10:36:46
![](https://img.aspxhome.com/file/2023/6/129006_0s.png)
基于jdk动态代理和cglib动态代理实现及区别说明
2022-04-11 00:32:44
Apache和Tomcat有什么区别_动力节点Java学院整理
2023-08-15 08:49:44
![](https://img.aspxhome.com/file/2023/3/68783_0s.jpg)
android实现密码框右侧显示小眼睛
2023-01-26 19:54:59
![](https://img.aspxhome.com/file/2023/2/114302_0s.jpg)
Java内存区域管理详解
2023-11-10 23:44:42
![](https://img.aspxhome.com/file/2023/3/59173_0s.png)
Swagger实现动态条件注入与全局拦截功能详细流程
2023-11-23 13:41:05
Android短信验证码倒计时验证的2种常用方式
2022-06-23 17:27:42
![](https://img.aspxhome.com/file/2023/3/139543_0s.gif)
java基础检查和未检查异常处理详解
2023-10-25 11:10:25
![](https://img.aspxhome.com/file/2023/2/128232_0s.png)
C#实现多线程的Web代理服务器实例
2022-02-25 13:32:08
Android实现SQLite添加、更新及删除行的方法
2022-03-29 05:23:45
Java中的强引用,软引用,弱引用,虚引用的作用介绍
2023-08-27 11:03:28
![](https://img.aspxhome.com/file/2023/1/58411_0s.png)
android获取手机唯一标识的方法
2022-09-16 15:55:39
JavaWeb Spring依赖注入深入学习
2022-04-02 08:20:05
![](https://img.aspxhome.com/file/2023/3/125333_0s.jpg)