我在 Canvas 、矩形和屏幕尺寸方面遇到问题:
我不知道哪里出了问题,因为我在两个模拟器中使用了完全相同的代码,这里是代码:
云是一个普通对象,包含图像和一些移动它们的方法,这就是我创建云的方式:
云都在一个文件中,坐标是单个云所在的矩形。
for (byte i = 0; i < 4; i++) {
Cloud c;
if (i == 1) c = new Cloud(5, 5, 245, 145);
else if (i == 2) c = new Cloud(340, 30, 480, 130);
else if (i == 3) c = new Cloud(565, 30, 725, 130);
else c = new Cloud(830, 20, 980, 130);
c.SetX(0);c.SetY(i * 150);
//c.ReubicarNube();
Clouds.Add(c);
}
Cloud类的构造函数调用它来处理图像(Plain是cloud的父类(super class)):
public Plain(int ResourceImg, int left, int top, int right, int bottom){
this.img = BitmapFactory.decodeResource(Init.GetContext().getResources(), ResourceImg);
this.Width = right - left;
this.Height = bottom - top;
this.frameImg = new Rect(left, top, right, bottom);
this.rect = new Rect(0, 0, this.Width, this.Height);
Log.v("Plains", this.frameImg.toString() + " " + this.rect.toString());
}
这就是我画画的方式:
public void draw(Canvas canvas) {
canvas.drawBitmap(img, frameImg, rect, Init.PaintFilter);
//canvas.drawbi
}
在此先感谢您的帮助!
最佳答案
我做到了!
我忘了把图像放在 drawable-hdpi 文件夹中!这就是我无法工作的原因!!
谢谢!
关于android - 图像矩形和屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18679530/