android开发闪动的TextView

释放双眼,带上耳机,听听看~!
package 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;
/**
* Created by abc on 2017/3/27.
*/
public class TextViewRect extends TextView {
Paint mPaint1,mPaint2;
public TextViewRect(Context context) {
super(context);
}
public TextViewRect(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TextViewRect(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public TextViewRect(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (matrix!=null){
mTranslate += mViewWidth/5;
if (mTranslate>2*mViewWidth){
mTranslate =- mViewWidth;
}
matrix.setTranslate(mTranslate,0);
mLineraGradient.setLocalMatrix(matrix);
postInvalidateDelayed(100);
}
}
int mTranslate;
int mViewWidth;
Matrix matrix;
LinearGradient mLineraGradient;
@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){
mPaint1 = getPaint();
mLineraGradient = new LinearGradient(0,0,mViewWidth,0,new int[]{Color.BLUE,0xffffff,Color.BLUE},null, Shader.TileMode.CLAMP);
mPaint1.setShader(mLineraGradient);
matrix = new Matrix();
}
}
}
}

 

人已赞赏
Android文章

取消androidStudio打开时默认打开上一个项目

2020-1-27 22:44:13

Android文章

android开发jxl对excel进行读、写、修改操作,设置excel列宽

2020-1-28 7:28:39

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索