在运行时管理表行的视图
在我的应用程序中,我在运行时创建并显示一个表。该表是在 Activity 类中开发的。一切工作正常,唯一的问题是桌子的视图。表中有四个连续的文本视图。它们相邻显示而不分开。我怎样才能在文本视图之间有一定的空间来制作正确的视图。
text1.setText("24/02/2011"); //TextView text
text2.setText("Andy"); //TextView text
text3.setText("3"); //TextView text
text4.setText("Repeat"); //TextView text
tableRow.addView(text1); //TableRow tableRow
tableRow.addView(text2); //TableRow tableRow
tableRow.addView(text3); //TableRow tableRow
tableRow.addView(text4); //TableRow tableRow
dueTL.addView(tableRow); //TableLayout dueTL
它显示的数据如下:24/02/2011Andy3Repeat
In my application i am creating and displaying a table at runtime. The table is developed in an Activity class. Everything working fine, only issue is the view of the table. There are four textviews in a row in the table. they are shown adjacently without seperation. How could i make a proper view with a definite space between textviews.
text1.setText("24/02/2011"); //TextView text
text2.setText("Andy"); //TextView text
text3.setText("3"); //TextView text
text4.setText("Repeat"); //TextView text
tableRow.addView(text1); //TableRow tableRow
tableRow.addView(text2); //TableRow tableRow
tableRow.addView(text3); //TableRow tableRow
tableRow.addView(text4); //TableRow tableRow
dueTL.addView(tableRow); //TableLayout dueTL
It display the data like : 24/02/2011Andy3Repeat
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以为每个
TextView
添加weight
,同时确保您的TableView
的宽度具有fill_parent
。另请检查TextView
的padding
和margins
我希望这会有所帮助
You can add
weight
to eachTextView
, also be sure that yourTableView
hasfill_parent
in its width. Also check thepadding
andmargins
of theTextView
sI hope this helps
如果由于某种原因设置权重不适合您的情况,请查看 http://developer.android.com/reference/android/widget/TextView.html
If for some reason setting weights doesn't work for your situation, take a look at padding, paddingBottom, paddingLeft, paddingRight, and paddingTop in http://developer.android.com/reference/android/widget/TextView.html
您可以手动向“setText”中的字符串添加空格,也可以在 TextView 上以 XML (
layout_marginRight
) 或通过代码 (<代码>布局参数)。You could either manually add a space to the strings in "setText" or you could set a right margin, if the surrounding ViewGroup supports it, on the TextViews either in XML (
layout_marginRight
) or via Code (LayoutParams
).