android中如何设置表格列
我在设置表行(包含文本视图)的布局参数时遇到一些困难。
我想添加一些列以获得良好的布局。我正在动态地做。 (在代码中)
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bye"/>
</TableRow>
我希望这两个文本视图成为两列并相应地在屏幕上布局。
I am having some difficulty setting layout parameters of table rows (containing text views).
I want to add some columns to get a good layout. I am doing it dynamically. (in code)
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bye"/>
</TableRow>
I want these two textviews to become two columns and layout on screen accordingly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经编写的内容实际上应该已经创建了两列,问题是它们可能不会像您期望的那样位于屏幕上 - 列将尽可能窄。 Android布局中的TableLayout标签有几个属性。其中之一是拉伸列 - 如果给定,所描述的列将被拉伸,以便填充所有指定的宽度。如果您需要均匀拉伸所有列,请使用星号,如果您希望拉伸任何特定列以覆盖剩余空间,请使用其基于 1 的索引(您可以指定一组索引)。请参阅此处:
顺便说一句,如果您只需要一行,您可以使用 LinearLayout 和orientation =“horizontal”执行相同的操作。如果您有多行,请记住您实际上正在处理表格 - 列中的所有行都将恰好位于另一行之上,并且最宽的行将决定列的宽度。
The thing you have already written should actually already create two columns, the thing is that they might not situate as you expect on the screen - the columns will be as narrow as possible. TableLayout tag in the Android layout has several attributes. One of them is the stretch columns - if given the described columns will be stretched so that to fill all the designated width. If you need all of them stretched evenly use star, if you want any specific column to be stretched covering the remaining space use its 1 based index (you can specify a group of indices). See here:
By the way if you need just a single row you might be able to do the same with LinearLayout and orientation="horizontal". If you have several rows, keep in mind that you are really dealing with table - all rows of a column will be situated exactly one above the other and the widest row will determine the width of the column.