TextView add to GridLayout dynamically

前端 未结 1 356
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 19:01

I have a problem, that i dont know how can i add a textview to a gridlayout. I have an xml:



        
相关标签:
1条回答
  • 2021-01-23 19:31
    GridLayout gv = (GridLayout) findViewById(R.id.gridlayout);
    TextView tv = new TextView(context);
    tv.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
    tv.setText("TextView);
    LayoutParams params = new LayoutParams(Set your column and row information as params);
    tv.setLayoutParams(params);
    gv.addView(tv);
    

    You can't paste the code in and it will need to be tested and changed to fit (it won't just work). But it should give you the general idea.

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