对现有控件进行拓展
来源:互联网 发布:mac地址表包括vlan吗 编辑:程序博客网 时间:2024/05/22 02:15
写的带有带有背景和边框
package com.example.administrator.youku_animi.MyView;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.LinearGradient;import android.graphics.Paint;import android.widget.TextView;/** * Created by Administrator on 2017/7/22 0022. */public class MyTextView extends TextView{ Paint mPaint1 = null; Paint mPaint2 = null; LinearGradient mLinearGradient = null; public MyTextView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { mPaint1 = new Paint(); mPaint1.setColor(getResources().getColor(android.R.color.holo_blue_light)); mPaint1.setStyle(Paint.Style.FILL); mPaint2 = new Paint(); mPaint2.setColor(Color.YELLOW); mPaint2.setStyle(Paint.Style.FILL); //Preconcat the current matrix with the specified translation canvas.drawRect( 0, 0, getMeasuredWidth(), getMeasuredHeight(), mPaint1 ); canvas.drawRect( 10, 10, getMeasuredWidth() - 10, getMeasuredHeight() - 10, mPaint2 ); //Saves the current matrix and clip onto a private stack. canvas.save(); //Preconcat the current matrix with the specified translation canvas.translate(10, 0); super.onDraw(canvas); //This call balances a previous call to save(), and is used to remove all modifications to the matrix/clip state since the last save call. canvas.restore(); }}
闪动字体的TextView
package com.example.administrator.youku_animi.MyView;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.widget.TextView;/** * Created by Administrator on 2017/7/22 0022. */public class MyTextView2 extends TextView{ int mTranslate ; int mViewWidth; LinearGradient mLinearGradient = null; Paint mPaint; Matrix matrix = null, matrix1; public MyTextView2(Context context) { super(context); } @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, 0, mViewWidth, 0, new int[]{ Color.RED, 0xffffffff, Color.BLUE }, null, Shader.TileMode.REPEAT ); mPaint.setShader(mLinearGradient); matrix = new Matrix(); } } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (matrix != null) { mTranslate += mViewWidth / 10; } matrix.setTranslate(mTranslate, 0); mLinearGradient.setLocalMatrix(matrix); postInvalidateDelayed(100); }}
阅读全文
0 0
- 对现有控件进行拓展
- Android View之对现有控件进行拓展实例
- 对现有的控件进行拓展,以TextView为例,为文本加彩虹渐变效果
- Android群英传笔记-3.6.1对现有控件进行拓展(TextView 实现闪动效果)
- android群英传笔记——对现有控件进行拓展(闪动的文字效果)
- Android群英传--对现有控件进行拓展(动态的文字闪动效果)
- 《Android 群英传》读书笔记:自定义 View 之对现有控件进行拓展
- 自定义控件之对现有控件拓展(一)
- 自定义控件之对现有控件拓展(一)
- Android 控件架构与自定义控件(一)对现有控件进行扩展
- android群英传之自定义View--对现有控件进行扩展(1)
- NSFileHandle 对现有文件进行读写
- 对二维数据进行边界拓展
- 对UGUI的GridLayoutGroup组件进行拓展
- Android自定义控件之对原生控件的拓展
- Android自定义控件之对原生控件的拓展
- 使用PowerDesigner 15对现有数据库进行反向工程
- 对现有Hive的大表进行动态分区
- 同步、异步、阻塞、非阻塞的理解
- JavaWeb——文件上传和下载.
- 实现一棵二叉树的层序遍历
- 合租分房策略
- HIbernate第一课--基本原理,配置
- 对现有控件进行拓展
- 2016校招腾讯研发岗笔试题---递归法求解格雷码
- Git使用总结
- 为什么使用 fftshift(fft(fftshift(x))) 而不是 fft(x)
- Java关键字之synchronized
- 泛型
- 丑数
- Manifest merger failed Suggestion: add 'tools:replace=“Android:value”' to <meta-data> element at And
- 【bzoj3343】教主的魔法