I created a custom SurfaceView, and i am trying to find a solution to match my surfaceview dimension to android screen dimension (dynamically)
我创建了一个自定义的SurfaceView,我试图找到一个解决方案,以匹配我的surfaceview尺寸到android屏幕尺寸(动态)
GameSurface:
GameSurface:
public class GameSurface extends SurfaceView implements SurfaceHolder.Callback {
public GameSurface(Context context) {
super(context);
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
screenW = metrics.widthPixels;
screenH = metrics.heightPixels;
gameLoopThread = new GameLoopThread(getHolder(), this);
basketball = new Basketball(context, screenW, screenH);
hoop = new Hoop(context, screenW, screenH);
background = new Background(context);
score = 0;
getHolder().addCallback(this);
}
MainActivity:
MainActivity:
gameSurface = new GameSurface(this);
setContentView(gameSurface);
gameLoopThread = gameSurface.getGameLoopThread();
I did try using Displaymetrics, upon testing it on physical device it match the top and left corner but bottom and right corner isnt.
我确实试过使用DisplayMetrics,在物理设备上测试时,它与左上角匹配,但右下角不匹配。
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!