How to dynamically set layout parameters in Android?

后端 未结 2 1364
半阙折子戏
半阙折子戏 2021-02-08 01:04

I have these text fields which I generated dynamically. But I can\'t seem to set layout parameters for them. Please tell me what I\'m doing wrong.

I\'m able to generate

相关标签:
2条回答
  • 2021-02-08 01:44

    You have to use TableRow.LayoutParams instead of LinearLayout.LayoutParams

    Replace your code

    LinearLayout.LayoutParams fieldparams = new LinearLayout.LayoutParams(10, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
    

    with the below code.

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

    Its working fine. Let me know what happened. :-)

    0 讨论(0)
  • 2021-02-08 01:52

    You are adding Table Row into table so use TableLayout.LayoutParams instead of LinearLayout.LayoutParams.As we use LayoutParam according to parent in which we are going to add

    0 讨论(0)
提交回复
热议问题