在 TableRow 中使用的 Android Inflate 布局 [英] Android Inflate layout to use inside TableRow

查看:23
本文介绍了在 TableRow 中使用的 Android Inflate 布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 android 中动态构建一个表.但是,当我尝试扩充视图(例如 table_cell.xml)并将其添加到我的表格行时,没有任何显示:

I'm trying to build a table in android dynamically. But when I attempt to inflate a view, for instance, table_cell.xml, and add it to my table row, nothing appears:

TableLayout tableLayout = (TableLayout)rootView.findViewById(R.id.tableLayout);

View tableCell = getActivity().getLayoutInflater()
                    .inflate(R.layout.table_cell, container, false);

TableRow tableRow = new TableRow(getActivity());

tableRow.addView(tableCell);
tableLayout.addView(tableRow);

另一方面,如果我只是手动创建一个 TextView,然后将其添加到行中,它似乎工作正常.谁能帮我弄清楚为什么添加膨胀的布局不起作用?

On the other hand, if I just create a TextView manually, then add it to the row, it seems to work fine. Can anyone help me figure out why adding an inflated layout doesn't work?

推荐答案

你应该试试getActivity().getLayoutInflater() .inflate(R.layout.table_cell, tableRow, true);

在这种情况下,您不应在 tableRow 上手动添加 tableCell 视图,因为 inflator 方法会处理该问题,因为我们传递了 true ..

And you should not add the tableCell view on the tableRow manually in this case as the inflator method takes care of that since we pass true ..

这篇关于在 TableRow 中使用的 Android Inflate 布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆