【发布时间】:2014-03-26 14:27:20
【问题描述】:
有很长的字符串。我将长字符串分成单词并为每个单词设置 TextView。 (你可以问我为什么需要这个功能?当用户点击 textview(word) 时,应用程序会显示单词的含义)
...
TextView tv = new TextView(this);
tv.setTextSize(24);
tv.setText(word);
ll.addView(tv);
...
我的线性布局:
<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
二字
单词3
如果我把它放在水平方向,它只是把所有的词放在一行:
单词 1,单词 2,单词 3
结果word4、word5、word6不可见。
如何以这种方式以编程方式添加TextViews?
【问题讨论】:
标签: android android-layout android-linearlayout textview