【发布时间】:2018-09-19 16:33:37
【问题描述】:
我想将TableRow 动态添加到TableLayout 的上方。我使用打击代码:
在我的活动中:
TableLayout table = (TableLayout)ChatActivity.this.findViewById(R.id.tblChats);
for(int i = 1; i < 10; ++i)
{
TableRow row = (TableRow)LayoutInflater.from(ChatActivity.this).inflate(R.layout.chat_row, null);
((TextView)row.findViewById(R.id.attrib_name)).setText("A");
((TextView)row.findViewById(R.id.attrib_value)).setText(i + "");
table.addView(row);
}
table.requestLayout();
chat_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/attrib_name"
android:textStyle="bold"/>
<TextView android:id="@+id/attrib_value"
android:gravity="right"
android:textStyle="normal"/>
</TableRow>
如您所知,这些代码在TableLayout 的底部添加了TableRow。
有没有办法把它加到TableLayout上面?
【问题讨论】:
-
是的,我想做。
标签: android view add tablelayout tablerow