在Android中生成对称表
我在使用 Android 的 TableLayout 时遇到了一些问题。我想创建一个具有对称行/列的表,即一个布局,其中的每个 TextView 都像其他所有 TextView 一样分配完全相同的空间量,无论附加什么文本。
重要的是,这可以通过使用 Java 代码而不是 XML 文件来完成。
最好知道这种布局需要两个桌子相邻,即每个桌子只有屏幕尺寸的 50%。我想这会使几个LayoutParameter不可用(例如FILL_PARENT)?
这就是我尝试过的:
for (String s : buffer) {
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(0x00, LayoutParams.WRAP_CONTENT, 1f));
tv.append(s);
row.addView(tv, new TableRow.LayoutParams(LayoutParams.FILL_PARENT));
}
不过看起来仍然很糟糕。
I got some trouble with the TableLayout Android. I wanna create a table with symmetric rows/columns, i.e. a layout where every TextView in it gets allocated exactly the same amount of space like all the others, no matter what text has been appended to it.
It's important that this can be done by the use of Java-code, not the XML-files.
It would be probably good to know that this layout requires two tables to be next to each other, i.e. every table has just 50% of the screen size. I suppose this makes several LayoutParameter unavailable (e.g. FILL_PARENT)?
This is what I tried:
for (String s : buffer) {
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(0x00, LayoutParams.WRAP_CONTENT, 1f));
tv.append(s);
row.addView(tv, new TableRow.LayoutParams(LayoutParams.FILL_PARENT));
}
Still looks bad though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将创建两列,它们以有序的方式共享宽度。
编辑:同样的事情,但现在在代码中:
This will create two columns that share's the width in an orderly fashion.
Edit: Same thing, but now in code: