当黑色条向右前进时,“50%”文本颜色动态变为白色.这可能是使用“简单”的解决方案吗?我查了一下PorterDuff,colorFilters,xFermodes,似乎没什么用.有任何想法吗? ATM我的代码看起来像这样:
Rect r = new Rect(1,1,m_wIDth-1,m_height-1); canvas.drawRect(r,pWhiteFill); r = new Rect(1,progressWIDth,pBlackFill); canvas.drawText(String.valueOf(progress)+"%",m_wIDth/2,m_height/2,pBlackTxtM);
有没有办法修改pBlackTxtM绘画,以根据“在画布上”下方绘制的内容来更改颜色?
解决方法 即使问题很老,我也想分享解决方案.你不能使用“反转”Paint来做到这一点,但你可以使用剪裁来实现它.
想法是两次绘制文本,一次是黑色,一次是白色,同时设置剪切区域以匹配条的各个部分.
这里有一些代码来概述这个想法:
// store the state of the canvas,so we can restore any prevIoUs clipPingcanvas.save();// note that it's a bad IDea to create the Rect during the drawing operation,better do that only once in advance// also note that it might be sufficIEnt and faster to draw only the white part of the barRect r = new Rect(1,m_height-1);canvas.drawRect(r,pWhiteFill);// this Rect should be created when the progress is set,not on every drawing operationRect r_black = new Rect(1,m_height-1);canvas.drawRect(r_black,pBlackFill);// set the clipPing region to the black part of the bar and draw the text using white inkString text = String.valueOf(progress)+"%";canvas.cliprect(r_black);canvas.drawText(text,pWhiteTxtM);// draw the same text again using black ink,setting the clipPing region to the complementary part of the barcanvas.clipRect(r,Region.Op.XOR);canvas.drawText(text,pBlackTxtM);canvas.restore();总结
以上是内存溢出为你收集整理的android – 根据背景反转油漆颜色全部内容,希望文章能够帮你解决android – 根据背景反转油漆颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)