我正在开发一个android项目,我有一个表格布局。我在表格标题的XML布局文件中有一行表格布局。表格的其余部分是根据API的结果动态填充的。将视图添加到表格布局的底部
我将视图添加到表格布局,但我动态添加的行出现在表格标题上方。
下面是我的XML布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar" />
<TableLayout android:id="@+id/tblAuthenticatedDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:shrinkColumns="false"
android:layout_margin="10dp"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cardToolbar">
<TextView
android:text="Device Name"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold"
android:padding="10dp"
android:textColor="@color/white" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="Last Logged In"
android:textStyle="bold"
android:padding="10dp"
android:textColor="@color/white" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:text="From"
android:textStyle="bold"
android:padding="10dp"
android:textColor="@color/white"/>
</TableRow>
</LinearLayout>
下面是我怎么了填充表的其余部分
JSONArray dataObject = jsonObject.getJSONArray(Defines.JSONElements.DATA);
for (int i = 0; i < dataObject.length(); i++)
{
TableRow row = (TableRow)getLayoutInflater().inflate(R.layout.table_row_layout, tblAuthenticatedDevices, false);
JSONObject deviceData = dataObject.getJSONObject(i);
TextView txtDeviceName = new TextView(AuthenticatedDevices.this);
txtDeviceName.setText(deviceData.getString("DeviceName"));
row.addView(txtDeviceName);
TextView txtLastLoggedIn = new TextView(AuthenticatedDevices.this);
txtLastLoggedIn.setText(deviceData.getString("LastLoggedIn"));
row.addView(txtLastLoggedIn);
TextView txtLocation = new TextView(AuthenticatedDevices.this);
txtLocation.setText(String.format("%s - %s", deviceData.getString("Country"), deviceData.getString("City")));
row.addView(txtLocation);
tblAuthenticatedDevices.addView(row);
}
只是再次重申,该行数据,我动态地添加到该表格出现在我添加到我的XML布局的行标题上方。我希望行标题出现,然后在下面显示我添加到表中的行。
感谢您提供的任何帮助。