gpt4 book ai didi

Java - 尝试在此 forLoop 的每次迭代上绘制图像

转载 作者:行者123 更新时间:2023-12-02 01:23:43 24 4
gpt4 key购买 nike

所以我有这个 forLoop,它用导航单元填充屏幕。我想在填充每个元素时为它们设置背景颜色。主要问题是我无法弄清楚将 Canvas 设置为绘图函数的内容,如果这甚至是正确的方法的话。

单元格创建循环:

    // creates cells
mCells = new NavCell[mCellRows][mCellCols];
//System.out.println( "Rows " + mCellRows + " and Cols: " + mCellCols);
for (int j = 0; j < mCellRows; j++) {
System.out.println("inside rows " + j);
// if (mCells[j] != null) {
for (int i = 0; i < mCellCols; i++) {
System.out.println("inside columns " + i);

mCells[j][i] = new NavCell();
drawCells(null, j, i);
mCells[j][i].setBounds(
i * CELL_SIZE,
j * CELL_SIZE,
(i * CELL_SIZE) + CELL_SIZE,
(i * CELL_SIZE) + CELL_SIZE);


System.out.println("Hello Matt" + j);




System.out.println("Lazer-2 " + mCells);
}
}

绘制方法(当前为图像设置,因为 setBackground 不起作用)

     public void drawCells(Canvas canvas, int X, int Y) {
mBMPStart = BitmapFactory.decodeResource(getResources(), R.drawable.start);
canvas.drawBitmap(mBMPStart, X, Y, null);
}

最佳答案

是时候回顾一下绘画了!

安卓: https://developer.android.com/training/custom-views/custom-drawing#java

AWT: https://youtu.be/2l5-5PMUc5Y

您将需要添加一种控制绘图迭代的方法,可以通过添加按钮或使用包含重绘调用或类似内容的线程。

关于Java - 尝试在此 forLoop 的每次迭代上绘制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57599408/

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