gpt4 book ai didi

CustomView (surfaceview) does not match screen dimension (dynamically)(CustomView(Surface Eview)与屏幕尺寸(动态)不匹配)

转载 作者:bug小助手 更新时间:2023-10-25 15:20:47 30 4
gpt4 key购买 nike



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,在物理设备上测试时,它与左上角匹配,但右下角不匹配。


更多回答
优秀答案推荐
更多回答

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com