Skip to content Skip to sidebar Skip to footer

Textview Add To Gridlayout Dynamically

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

Solution 1:

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.


Post a Comment for "Textview Add To Gridlayout Dynamically"