在 Android 编码方面,我是新手。作为第一个项目,我决定移植 ZX Spectrum 游戏。我准备了汽车的位图框架和即将根据屏幕尺寸缩放的按钮。我将图像放在“drawable”和“drawable-hdpi”文件夹中,它似乎可以在我的 LG Leon 手机上使用,但不能在其他手机上使用。看起来图像没有缩放。 https://mechanism.fr/misc/not_scaled.png
这是我的代码:变量的声明:
Rect source1;
Rect dest1;
Rect arrow_box;
Rect left_box;
Rect right_box;
Rect up_box1;
Rect down_box1;
Rect up_box2;
Rect down_box2;
计算一对 Rect 尺寸的示例:
private void calculateDimensions(){
(...)
source1=new Rect(0,0,128,100);
arrow_box=new Rect(0,0,300,300);
left_box=new Rect((int)(0+boxxy/2),(int)(wysokosc*0.7),(int)(0+boxxy/2+boxxy),(int)(wysokosc*0.7+boxxy));
以及负责绘图的代码:
Paint drawPaint2 = new Paint();
canvas.drawBitmap(arrow_left_off,arrow_box,left_box,drawPaint2);
canvas.drawBitmap(arrow_right_off,arrow_box,right_box,drawPaint2);
canvas.drawBitmap(arrow_up_off,arrow_box,up_box1,drawPaint2);
canvas.drawBitmap(arrow_down_off,arrow_box,down_box1,drawPaint2);
canvas.drawBitmap(arrow_up_off,arrow_box,up_box2,drawPaint2);
canvas.drawBitmap(arrow_down_off,arrow_box,down_box2,drawPaint2);
创建画布视图后计算尺寸:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
kanwas=new CanvasV(this);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(kanwas);
getDimensions();
calculateDimensions();
updateScreen();
}
我不太明白似乎是什么问题。
我试图将图像复制到“drawable”和“drawable-hdpi”文件夹