画布的密度 [英] Canvas's density

查看:98
本文介绍了画布的密度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在onDraw函数中获取画布"的密度.如果我在仿真器c.getDensity()中运行代码,其中"c"是我的Canvas,则得到320,这是我期望的密度.但是,当我在实际的手机上运行此代码时,相同的函数返回0.如您所想,视觉结果从根本上是不同的...

I'm having trouble with getting the Canvas's density in my onDraw function. If I run the code in the emulator, c.getDensity(), where "c" is my Canvas, I get 320, which is the density I expect. But when I run this code on my actual phone, the same function returns 0. As you can imagine, the visual result is then fundamentally different...

从xml文件或onDraw函数定义位图背景没有任何区别.

Defining the bitmap background either from the xml file or from the onDraw function doesn't make any difference.

您知道这种行为的原因吗?

Do you have any idea for the cause of this behaviour?

使用的Android版本为4(仿真器为4.1.2,实际手机为4.1.1).

The version of Android used is 4 (4.1.2 for the emulator and 4.1.1 for the actual phone).

感谢您花时间来帮助我.

Thanks for the time you will spend trying to help me.

推荐答案

在我的实际手机上,getDensity返回的密度为0,因为它被配置为强制使用GPU.禁用此选项后,将返回正确的密度320.

On my actual phone, the density returned by getDensity was 0 because it was configured to force the use of the GPU. With this option disabled, the correct density of 320 is returned.

这篇关于画布的密度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆