5

我正在尝试在 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);

谁能建议这里有什么问题?

谢谢。詹姆士

4

1 回答 1

0

也许主要的 LinearLayout 没有添加活动 contentView。因为它是动态创建的,而不是附加其他视图。

于 2013-09-27T10:17:52.090 回答