Android 安卓以编程方式添加的行拉伸不好(TableLayout)

Android 安卓以编程方式添加的行拉伸不好(TableLayout),android,android-tablelayout,programmatically-created,stretching,Android,Android Tablelayout,Programmatically Created,Stretching,我在XML文件中声明了一个TableLayout,它将显示分数,这些分数是通过编程方式通过行添加的。问题是,没有添加任何分数的布局看起来是这样的(应该是这样的): 但是,当添加分数行时,它如下所示: 我不明白为什么会发生这种情况,我希望看到柱子被很好地拉伸,没有明显的原因来解释这种行为。如果有人能帮助我,我将非常感激 提前谢谢,我的英语很抱歉 以下是我的XML和代码: XML: 活动: TableLayout table = (TableLayout) findViewById(R.

我在XML文件中声明了一个TableLayout,它将显示分数,这些分数是通过编程方式通过行添加的。问题是,没有添加任何分数的布局看起来是这样的(应该是这样的):

但是,当添加分数行时,它如下所示:

我不明白为什么会发生这种情况,我希望看到柱子被很好地拉伸,没有明显的原因来解释这种行为。如果有人能帮助我,我将非常感激

提前谢谢,我的英语很抱歉

以下是我的XML和代码:

XML:


活动:

 TableLayout table = (TableLayout) findViewById(R.id.scoresTable);
    createOrderedCSV(getApplicationContext(), 4, ":");
    ArrayList<String> scores = readScores("OrderedScoresCSV.csv");
    // Score rows
    for (int i = scores.size() - 1; i >= 0; i--) {
        String[] currentScore = scores.get(i).split(":");
        TextView mode = new TextView(this);
        mode.setText(currentScore[0]);
        TextView kana = new TextView(this);
        kana.setText(currentScore[2]);
        TextView diff = new TextView(this);
        diff.setText(currentScore[1]);
        TextView score = new TextView(this);
        score.setText(currentScore[4]);
        TextView date = new TextView(this);
        date.setText(currentScore[3]);

        TableRow row = new TableRow(this);
        row.addView(mode);
        row.addView(kana);
        row.addView(diff);
        row.addView(score);
        row.addView(date);
        table.addView(row, new TableLayout.LayoutParams(
                TableLayout.LayoutParams.FILL_PARENT,
                TableLayout.LayoutParams.WRAP_CONTENT));
    }
    TableRow buttonRow = new TableRow(this);
    Button eraseScores = new Button(this);
    eraseScores.setWidth(200);
    eraseScores.setHeight(60);
    eraseScores.setText("Erase Scores");
    buttonRow.setGravity(Gravity.CENTER_HORIZONTAL);
    buttonRow.addView(eraseScores);
    table.addView(buttonRow);
TableLayout table=(TableLayout)findViewById(R.id.scoresTable);
createOrderedCSV(getApplicationContext(),4,“:”);
ArrayList分数=readScores(“OrderedScoresCSV.csv”);
//记分行
对于(int i=scores.size()-1;i>=0;i--){
字符串[]currentScore=scores.get(i).split(“:”);
TextView模式=新的TextView(此模式);
mode.setText(currentScore[0]);
TextView kana=新的TextView(此);
kana.setText(currentScore[2]);
TextView diff=新的TextView(此);
差异设置文本(currentScore[1]);
TextView分数=新的TextView(本);
score.setText(currentScore[4]);
TextView日期=新的TextView(此);
date.setText(currentScore[3]);
TableRow row=新的TableRow(本);
row.addView(模式);
row.addView(假名);
row.addView(diff);
row.addView(score);
row.addView(日期);
table.addView(行,新的TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL\u父级,
TableLayout.LayoutParams.WRAP_CONTENT);
}
TableRow buttonRow=新的TableRow(此);
按钮=新按钮(此按钮);
设置宽度(200);
设置高度(60);
擦除分数。setText(“擦除分数”);
按钮Row.setGravity(重心水平);
按钮Row.addView(删除分数);
table.addView(按钮箭头);

这是由我在末尾添加的按钮行引起的。它被附加到第一列

 TableLayout table = (TableLayout) findViewById(R.id.scoresTable);
    createOrderedCSV(getApplicationContext(), 4, ":");
    ArrayList<String> scores = readScores("OrderedScoresCSV.csv");
    // Score rows
    for (int i = scores.size() - 1; i >= 0; i--) {
        String[] currentScore = scores.get(i).split(":");
        TextView mode = new TextView(this);
        mode.setText(currentScore[0]);
        TextView kana = new TextView(this);
        kana.setText(currentScore[2]);
        TextView diff = new TextView(this);
        diff.setText(currentScore[1]);
        TextView score = new TextView(this);
        score.setText(currentScore[4]);
        TextView date = new TextView(this);
        date.setText(currentScore[3]);

        TableRow row = new TableRow(this);
        row.addView(mode);
        row.addView(kana);
        row.addView(diff);
        row.addView(score);
        row.addView(date);
        table.addView(row, new TableLayout.LayoutParams(
                TableLayout.LayoutParams.FILL_PARENT,
                TableLayout.LayoutParams.WRAP_CONTENT));
    }
    TableRow buttonRow = new TableRow(this);
    Button eraseScores = new Button(this);
    eraseScores.setWidth(200);
    eraseScores.setHeight(60);
    eraseScores.setText("Erase Scores");
    buttonRow.setGravity(Gravity.CENTER_HORIZONTAL);
    buttonRow.addView(eraseScores);
    table.addView(buttonRow);