admin管理员组文章数量:1122846
I can't get anything to show up on screen. I have created a Empty Views Action then written the following code. (Copied from youtube where it works)
public class GamePanel extends SurfaceView implements SurfaceHolder.Callback {
private Paint redpaint = new Paint();
public GamePanel(Context context) {
super(context);
getHolder().addCallback(this);
redpaint.setColor(Color.RED);
}
@Override
public void surfaceCreated(@NonNull SurfaceHolder holder) {
Canvas c = holder.lockCanvas();
c.drawRect(50,50,100,100,redpaint);
holder.unlockCanvasAndPost(c);
}
@Override
public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
}
}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GamePanel(this));
}
}
I have checked all kinds of things:
- I have changed the background color to make sure I can see the view
- I have checked that
c
(the canvas fromlockCanvas()
) is not null - I have checked that visibility for this and parent is 0
And all other kinds of checks that ChatGPT said I should do
I have now narrowed the problem down to the emulator. I tried connecting my phone which seemed to fix the problem. However, since I would like to use the emulator this still poses a problem.
The emulator seems to be working fine but whatever I draw to the screen never shows up.
本文标签: javaCant draw anything on canvas using surfaceViewStack Overflow
版权声明:本文标题:java - Cant draw anything on canvas using surfaceView? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311443a1934739.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论