1

我正在制作一个益智游戏,我必须同时在屏幕上显示 16 个图像(4 X 4)。我正在尝试设置图像的高度和宽度,但高度和宽度的值没有改变图像大小。此外,只出现了 4 张图像而不是 16 张图像。我正在使用以下代码来显示图像:

   public void display()
    {
        LinearLayout llMain = new LinearLayout(this);
        for(int i=0;i<4;i++)
        {
            LinearLayout llRow = new LinearLayout(this);
            for(int j=i*4;j<tiles.length/4;j++)
            {
                ImageView iv = new ImageView(this);
                iv.setImageBitmap(tiles[j]);
                iv.setAdjustViewBounds(true);
                iv.setMaxHeight(tileHeight);
                iv.setMaxWidth(tileWidth);
                iv.setMinimumHeight(tileHeight);
                iv.setMinimumWidth(tileWidth);
                LayoutParams params =  new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                iv.setLayoutParams(params);
                llRow.addView(iv);
            }
            llMain.addView(llRow);
        }
        setContentView(llMain);
}

有人可以告诉我我做错了什么吗?

提前致谢

4

1 回答 1

0

尝试使用 LinearLayout 的 layout_weight 属性将屏幕划分为您需要的部分。您为不同零件设置的值的比率会使零件变大或变小。

于 2013-01-05T00:12:57.997 回答