我正在尝试在 Android 应用程序中的 Canvas 上绘制 GridView,如下所示,但屏幕上没有显示任何内容。
int width = 400;
int height = 400;
private String[] numbers = {"1", "2", "3", "4", "5", "6"};
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.YELLOW);
GridView gridview = new GridView(MainActivity.this);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, Android.R.layout.simple_list_item_1, numbers);
gridview.setAdapter(adapter);
LinearLayout layout = new LinearLayout(MainActivity.this);
layout.addView(gridview);
layout.measure(canvas.getWidth(), canvas.getHeight());
layout.layout(0, 0, canvas.getWidth(), canvas.getHeight());
layout.draw(canvas);
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setImageBitmap(bitmap);
谁能建议这里有什么问题?
谢谢。詹姆士