有很長的字符串。我將長串分成單詞併爲每個單詞設置TextView。 (?你可以問,爲什麼我需要這個功能,當用戶點擊的TextView(字),應用程序顯示了這個詞的含義)以編程方式將多個TextView添加到LinearLayout中
...
TextView tv = new TextView(this);
tv.setTextSize(24);
tv.setText(word);
ll.addView(tv);
...
我的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>
如果我把LinearLayout中的定位垂直,它將每個TextView放在新的行中。 例如:
字1
單詞2
WORD3
如果我把它在水平方向,它把所有的話只有一個行:
字1,字2,字3
在結果word4中,word5,word6不可見。
如何以這種方式編程添加TextViews?
首先,感謝您的回答。但是我問了如何在圖片中顯示的方式將textview添加到linearlayout中:TextViews的段落 – user3388473