自定义TextView
来源:互联网 发布:淘宝零食店排行榜 编辑:程序博客网 时间:2024/06/05 16:34
public class MyTextView extends TextView {
Paint mpaint1;Paint mpaint2;Paint paint;private int mwidth;private LinearGradient gradient;private Matrix matrix;private int speedX;private int i = 0;public MyTextView(Context context) { super(context); this.init();}public MyTextView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); this.init();}public MyTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); this.init();}private void init(){ this.mpaint1 = new Paint(); this.mpaint1.setColor(getResources().getColor(android.R.color.holo_blue_bright)); this.mpaint1.setStyle(Paint.Style.FILL); this.mpaint2 = new Paint(); this.mpaint2.setColor(Color.YELLOW); this.mpaint2.setStyle(Paint.Style.FILL); this.speedX = 0; this.mwidth = 0;}@Overrideprotected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); paint = getPaint(); mwidth = getMeasuredWidth(); //线性变换 this.gradient = new LinearGradient(0 , 0 , mwidth , 0, new int[]{Color.BLUE , Color.RED, Color.GREEN}, null, Shader.TileMode.CLAMP); paint.setShader(this.gradient); this.matrix = new Matrix();}@Overrideprotected void onDraw(Canvas canvas) { //这段代码对应第一个图 canvas.drawRect(0 ,0 ,this.getMeasuredWidth() ,this.getMeasuredHeight() ,this.mpaint1); canvas.drawRect(10 , 10 , this.getMeasuredWidth() - 10, this.getMeasuredHeight() - 10 , this.mpaint2); canvas.save(); canvas.translate(0 , 10); super.onDraw(canvas); canvas.restore();// }
}
//这段代码对应第二个动态图
if(this.matrix != null){
speedX += mwidth / 5;
if(speedX > 2 * mwidth)
speedX = -mwidth;
this.matrix.setTranslate(speedX , 0);
this.gradient.setLocalMatrix(matrix);
//每个10ms重新调用onDraw 话界面
this.postInvalidateDelayed(10);
}
0 0
- 自定义textview
- 自定义textview
- 自定义TextView
- 自定义TextView
- TextView自定义
- 自定义TextView
- 自定义textView
- 自定义TextView
- 自定义TextView
- 自定义TextView
- 自定义TextView 链接
- 自定义TextView字体
- [自定义控件学习]Textview
- android 自定义TextView
- android 自定义TextView
- 自定义TextView控件
- Android 自定义TextView超链接
- 自定义旋转TextView控件
- vim开发Node.js
- Spark集群搭建
- 偶数求和
- Palindromes _easy version
- Java多线程(一)- 基础概念
- 自定义TextView
- 09-S3C2440驱动学习(三)嵌入式linux-platform平台总线驱动程序及分离分层构建驱动框架
- lintcode(646)First Position Unique Character
- 复习时间
- Myeclipse:使用Servlet中文出现乱码解决方案
- 组合模式
- 双面柔性线路板网印中 要留意的疑问
- jq和js如何判断checkbox是否选中
- 奇异递归模板模式(Curiously Recurring Template Pattern,CRTP)