I am manually creating a SurfaceView in code and setting it as content view on my activity like this:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int width = displaymetrics.widthPixels;
int height = displaymetrics.heightPixels;
mainSurface = new MainSurface(getBaseContext());
mainSurface.getHolder().setFixedSize(width, height);
setContentView(mainSurface);
I then simply draw images like this on the canvas:
canvas = surfaceHolder.lockCanvas(null);
int id = context.getResources().getIdentifier("imageName", "drawable", context.getPackageName());
Bitmap image = BitmapFactory.decodeResource(context.getResources(), id);
canvas.drawBitmap(image, pos[0], pos[1], null);
surfaceHolder.unlockCanvasAndPost(canvas);
But things are strange… Some images/bitmaps are stretched and the positions work different from image to image so if I give two images the same position they are not placed the same place? It is like there are some layout management going on that I don’t know off, but how can that be? Should they not be absolute positions always when drawing on a SurfaceView?
I am totally puzzled!
EDIT
Ok it was because I only have images in the “drawable” folder, if I copy them to the “drawable-hdpi” they are not stretched! So to turn my question in another direction, can I make Android stop doing that? Can I make Android just use my images as-is even though if they only exist in the “drawable” folder and at the same time use those images (like the icon and such) that are in the different dpi folders?
It was because I only have images in the “drawable” folder, if I copy them to the “drawable-hdpi” they are not stretched!
EDIT: In fact if you want to use the same images for all screens and not have them resized by Android, you can place them in a “drawable-nodpi” folder