有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java扫雷器(不是算法,只是布局问题)

我正试图在Android studio中制作扫雷舰的布局。但它并没有在emulator上显示任何内容。它只是显示“应用程序名”不断停止。(是模拟器问题?还是代码问题?)。当我构建此代码时,没有任何红色的底部或错误标志。 这是我的密码

import 安卓.support.v7.app.AppCompatActivity;
import 安卓.os.Bundle;
import 安卓.widget.Button;
import 安卓.widget.TableLayout;
import 安卓.widget.TableRow;

public class MainActivity extends 
AppCompatActivity
{

    TableLayout table;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        table = (TableLayout) findViewById(R.id.tableLayout);

        TableRow tableRow = new TableRow(this);

        for(int i = 0; i < 9; i++)
        {
            table.addView(tableRow);
        }

        Button[][] buttons = new Button[9][9];

        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                buttons[i][j] = new Button(this);
            }
        }

        TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT, 1.0f);

        for(int i = 0; i < 9; i++)
        {
            for(int j = 0; j<9; j++)
            {
                buttons[i][j].setLayoutParams(layoutParams);
                tableRow.addView(buttons[i][j]);
            }
        }
    }
}`

我必须用这种方式制造扫雷艇
1.使用TableLayout的addView()方法制作9by9扫雷艇
2.把9张桌子排成一行
3.必须动态分配81个按钮和9个表格行。(xml文件中只能分配TableLayout)
4.我必须使用这个示例代码

(一)

TableLayout table; table = (TableLayout)findViewById(R.id.tableLayout);
TableRow tableRow = new TableRow(this);
table.addView(tableRow);

(二)

Button[][] buttons = new Button[9][9];
for (int i = 0; i < 9; i++) 
{ 
    for (int j = 0; j < 9; j++) 
    {
        buttons[i][j] = new Button(this);
    } 
}

(三)

TableRow.LayoutParams layoutParams =  new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1.0f); 
button[i][j].setLayoutParams(layoutParams);
tableRow.addView(buttons[i][j]);

共 (0) 个答案