本文實(shí)例為大家分享了Android顏色漸變滾動(dòng)展示的具體代碼,供大家參考,具體內(nèi)容如下

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();//獲得當(dāng)前繪制的Paint對(duì)象
mLinearGradient = new LinearGradient(
0,//漸變起始點(diǎn)x坐標(biāo)
0,//漸變起始點(diǎn)y坐標(biāo)
mViewWidth,//漸變結(jié)束點(diǎn)x點(diǎn)坐標(biāo)
0,//漸變結(jié)束點(diǎn)y坐標(biāo)
new int[]{
Color.BLUE, 0xffffffff,
Color.BLUE,Color.RED,Color.YELLOW},//顏色的int數(shù)組
null,//相對(duì)位置的顏色數(shù)組,可為null, 若為null,可為null,顏色沿漸變線均勻分布
Shader.TileMode.MIRROR);//平鋪模式
mPaint.setShader(mLinearGradient);//給這個(gè)paint設(shè)置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);//通過矩陣的方式不斷平移產(chǎn)生漸變效果
postInvalidateDelayed(100);
}
}
}
分享文章:AndroidTextview實(shí)現(xiàn)顏色漸變滾動(dòng)效果-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://www.chinadenli.net/article16/pohgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)、靜態(tài)網(wǎng)站、標(biāo)簽優(yōu)化、網(wǎng)站設(shè)計(jì)公司、域名注冊(cè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容