0
我想顯示tilemap的,但是當我跑我的應用程序,沒有什麼在屏幕上:C的Android tilemap的錯誤
public class MainActivity extends Activity {
LinearLayout tileMap;
int width, height = 1;
int[][] map = {
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tileMap = new LinearLayout(this);
generate(tileMap, this);
setContentView(tileMap);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
void generate(LinearLayout tileMap, Context context) {
for(int y = 0; y < height; y++) {
for(int x = 0 ; x < width; x++) {
ImageView tile = new ImageView(context);
tile.setImageResource(R.drawable.wall);
tileMap.addView(tile);
}
}
}
}
你能告訴我什麼是錯我的代碼? 我很確定這個問題在生成函數裏面......我已經試過去做一個ImageView數組,但它也沒有工作! 謝謝:)