Create TableLayout programmatically

后端 未结 5 1356
小蘑菇
小蘑菇 2020-12-02 17:30

I\'m trying to create a TableLayout programatically. It just won\'t work. The same layout in an xml file works though. This is what I have:

public class MyTa         


        
5条回答
  •  有刺的猬
    2020-12-02 17:55

    Your problem is at this line:

    b.setLayoutParams(new LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    

    You need to change LayoutParams to TableRow.LayoutParams:

    b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    

提交回复
热议问题