There is long string. I am dividing long string into words and setting TextView for each word. (You can ask why I need this function? When user clicks on textview(word), application shows the meaning of the word)
...
    TextView tv = new TextView(this);
                tv.setTextSize(24);
                tv.setText(word);
                ll.addView(tv);
...
My LinearLayout:
<LinearLayout
        android:id="@+id/llReader"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:orientation="vertical" >
    </LinearLayout>
If I put LinearLayout's orientation vertical, it is putting each TextView in new line. For example:
word1
word2
word3
If I put it in horizontal orientation, it is putting all words only in one line:
word 1, word 2, word 3
In result word4,word5, word6 is not visible.
How to add TextViews programmatically in this way?

You should add Horizontal LinearLayout in your Vertical LinearLayout:
<LinearLayout
    android:id="@+id/verticalLinear"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:id="@+id/horizontalLinear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
    </LinearLayout>
</LinearLayout>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With