动态添加的tableRows未显示

时间:2015-10-07 11:01:33

标签: android tablelayout tablerow

我得到了List stings,我希望在TableRows中添加尽可能多的strings list。我在同一个项目中的多个其他activity's中工作得很好。所以我复制了代码,它没有用。 TableRows没有显示。所以我评论了所有不必要的东西和debugged,所有代码都运行了,没有错误。但是TableRows仍未显示......是否有我忘记导入的内容?

进口:

import java.util.ArrayList;
import java.util.List;
import android.R.color;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableLayout.LayoutParams;

代码:

    TableLayout tl = (TableLayout) findViewById(R.id.MyTableLayout);

    for (int i =0; i< SomeList.size();i++){
        TableRow tr = new TableRow(this);
        TableLayout.LayoutParams p = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT, 1.0f);
        tr.setLayoutParams(p);
        tr.setBackgroundColor(color.black);
        tl.addView(tr);
    }

XML:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TableLayout
        android:id="@+id/kategori_tl"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    </TableLayout>

</ScrollView>

更新

因此,在评论中提供了一些帮助后,我注意到xml的主要LinearLayout具有高度wrap_content,所以我将其更改为match_parent。现在我得到静态TableRows,如果我在xml中添加它们但是动态我试图添加仍然没有。

0 个答案:

没有答案
相关问题