I'm trying to get my android application to look the same on all screen devices. I assume I have to do something regarding the density, I just can't figure it out. And while I have seen very similar questions to this I'm not getting clear answers or I'm just not understanding things resulting in inconsistent results.
So how do I get, for example, my game to look exactly the same on a Samsung Galaxy 7 as on an LG tablet?
Side note: I have looked into scaling the Canvas but can't quite figure out how to do this correctly.
Example
package com.haas.ryan.example;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
/**
* Created by Ryan on 8/4/2017.
*/
public class Drawing extends SurfaceView implements SurfaceHolder.Callback {
private Rect rect;
public Drawing(Context context) {
super(context);
getHolder().addCallback(this);
rect = new Rect(100, 100, 500, 500);
}
public void surfaceCreated(SurfaceHolder sh) {
Canvas canvas = sh.lockCanvas();
draw(canvas);
sh.unlockCanvasAndPost(canvas);
}
public void surfaceDestroyed(SurfaceHolder sh) {}
public void surfaceChanged(SurfaceHolder sh, int format, int w, int h) {}
public void draw(Canvas canvas) {
super.draw(canvas);
System.out.println("call");
Paint p = new Paint();
p.setColor(Color.RED);
canvas.drawRect(rect, p);
invalidate();
}
}
Device 1 Screenshot
Device 2 Screenshot
While it's a lot harder to tell on the emulator (my bad I chose 2 phones, should'be chosen a tablet) you can see that the rectangles don't take up the same amount of relative space. In fact on the larger screen the rectangle is actually smaller.

