我照抄的显示出来的界面是3X4的??
package com.example.xiaodipintu;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.os.Build;
public class MainActivity extends Activity {
/**利用二维数组创建若干个游戏小方块*/
private ImageView[][] iv_game_arr=new ImageView[3][5];
/**游戏主界面*/
private GridLayout gl_main_game;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*初始化游戏的若干个小方块*/
Bitmap bigBm=((BitmapDrawable)getResources().getDrawable(R.drawable.ic_onepiece)).getBitmap();
int tuWandH=bigBm.getWidth()/5;//每个游戏小方块的宽和高
for (int i = 0; i < iv_game_arr.length; i++) {
for (int j = 0; j < iv_game_arr[0].length; j++) {
Bitmap bm=Bitmap.createBitmap(bigBm,j*tuWandH,i*tuWandH,tuWandH,tuWandH);
iv_game_arr[i][j]=new ImageView(this);
iv_game_arr[i][j].setImageBitmap(bm);//设置每一个游戏小方块的图案
iv_game_arr[i][j].setPadding(2, 2, 2, 2);//设置方块之间的间距
}
}
/*初始化游戏界面,并添加若干个小方块*/
gl_main_game=(GridLayout)findViewById(R.id.gl_main_game);
for (int i = 0; i < iv_game_arr.length; i++) {
for (int j = 0; j < iv_game_arr[0].length; j++) {
gl_main_game.addView(iv_game_arr[i][j]);
}
}
}
}