为什么我的android应用程序崩溃?

时间:2014-08-05 20:14:10

标签: android

为什么在我的手机上应用程序正在运行,但在我的平板电脑上崩溃?

xml代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/shaam" >
<ImageView
    android:id="@+id/imageView2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/note" />
<GridLayout
    android:id="@+id/gridLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:columnCount="3"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp" >
</GridLayout>

java代码:

Button[][] board_button = new Button[3][1];
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    crate_board();
}
public void crate_board(){
    GridLayout gridLayout1 = (GridLayout)findViewById(R.id.gridLayout2);
    Display display = getWindowManager().getDefaultDisplay();
    Point screenSize = new Point();
    display.getSize(screenSize);    
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            board_button[i][j] = new Button(this);  
            LayoutParams xxx = new LayoutParams(screenSize.x/3-(10*2), screenSize.x/3-(10*2)) ;
            board_button[i][j].setLayoutParams(xxx);
            board_button[i][j].setBackgroundResource(R.drawable.x);
            gridLayout1.addView(board_button[i][j]);
        }
    }
}

在我的手机中

enter image description here

我的平板电脑中的

enter image description here

当我将代码更改为:

Button[][] board_button = new Button[3][4];
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    crate_board();
}
public void crate_board(){
    GridLayout gridLayout1 = (GridLayout)findViewById(R.id.gridLayout2);
    Display display = getWindowManager().getDefaultDisplay();
    Point screenSize = new Point();
    display.getSize(screenSize);    
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            board_button[i][j] = new Button(this);  
            //LayoutParams xxx = new LayoutParams(screenSize.x/3-(10*2), screenSize.x/3-(10*2)) ;
            //board_button[i][j].setLayoutParams(xxx);
            board_button[i][j].setBackgroundResource(R.drawable.x);
            gridLayout1.addView(board_button[i][j]);
        }
    }
}

应用正常运作!

电话:

enter image description here 片剂:

enter image description here

我该如何解决问题?

............................................... .................................................. .................................................. .................................................. .................................................. .................................................. .................................................. .................................................. .................................................. ........

0 个答案:

没有答案