Android的 - 使用PNG文件在画布上设置背景 [英] Android - Setting background on canvas using PNG file

查看:845
本文介绍了Android的 - 使用PNG文件在画布上设置背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置画布 .png文件作为背景在我的应用程序。我做了一个图像480 * 800,并用这个方法:

I'm trying to set a .PNG file as background on Canvas in my app. I've made an image 480 x 800 and used this method:

canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), 
                  R.drawable.image_1), 0, 0, null);

我已经开始仿真器(WVGA800),但我的形象看起来比设备的屏幕更大。

I've started an emulator (WVGA800) but my image looks greater than screen of the device.

我如何调整本图片或我应该用什么样的方法,使这一形象旗鼓相当。

How do I resize this image or what kind of methods should I use to make this image well-matched.

其次,有没有什么办法让这样的通用背景的不同屏幕分辨率的设备?

Secondly, is there any way to make backgrounds like this universal for devices with different screen resolutions?

感谢您提前。

推荐答案

你在哪里放的形象呢?如果它在绘或绘制,MDPI,它会比你告诉什么更大,因为WVGA800具有高密度(华电国际)。

where did you put the image? if it's in the drawable or the drawable-mdpi , it will be larger than what you've told , since WVGA800 has a high density (hdpi) .

即使你把它放在绘制,华电国际的文件夹,它会为WVGA800工作,但可能无法在其他设备上,它们具有不同的分辨率和宽高比显示良好。

even if you put it on the drawable-hdpi folder , it will work for WVGA800 , but it might not show well on other devices , which have different resolutions and aspect ratio .

您需要处理缩放和宽高比保持(如果你愿意的话)。否则,你将不得不在其他设备上同样的问题。

you need to handle the scaling and keeping of aspect ratio (if you wish) . otherwise , you will have the same problems on other devices.

这篇关于Android的 - 使用PNG文件在画布上设置背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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