简体   繁体   English

Android:我调用canvas.scale()后文本变得模糊

[英]Android:Text became blurred after I call canvas.scale()

When I want to enlarge my custom view text by using canvas.scale(),the text became blurred,as follows: 当我想使用canvas.scale()放大自定义视图文本时,文本变得模糊,如下所示:

@override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.translate(50,50 );
canvas.scale(mDpi/72, mDpi/72);
canvas.drawText("Stackoverflow!", 50, 50, mPaint);
}

the mDpi is 320,when it runs in a phone,it is blurred;However,when the code runs in nexus 10,it's normal!Somebody can tell me why? mDpi是320,当它在电话中运行时,它会模糊;但是,当代码在nexus 10中运行时,这是正常的!有人可以告诉我为什么吗?

I have got the solution! 我有解决方案!

private void closeHardwareAcceleration() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}

Because after api 11,view is draw with HardwareAcceleration,just close it! 因为在api 11之后,使用HardwareAcceleration绘制视图,所以只需将其关闭!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM