Q:

adding textviews to linear layout in .java file

I am having linear layout with orientation horizontal in my XML file and i am trying to add text views using below code.
LayoutParams lparams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText("Sample");
myLinearLayout.addView(tv);

Adding 5 text views in the similar fashion looks fine but if am trying to add more text views they are moving out the screen.
I know using horizontal orientation aligns all views in horizontal direction. But how can i make changes to my design/code so that, the hidden text views automatically moves to the next line.
Can anyone suggest me.
Thanks in advance.

A:

LinearLayout is either horizontal or vertical, but no both.
You can use GridLayout, maybe this fits your needs better.

