我正在尝试动态添加TableRow取决于我从服务器获得的请求但是当我运行应用程序时没有发生任何事情,否则表头从右侧推送。
@SuppressLint("NewApi")
protected void getClientTransaction(JSONArray transactionsArrayInfo)
{
int transactionsArraySize = transactionsArrayInfo.length();
for(int i = 0 ; i < transactionsArraySize ; i++ )
{
final String senderID = transactionDetails.getString("src_mymoid");
runOnUiThread(new Runnable() {
public void run()
{
try
{
TableRow row = new TableRow(Transactions.this);
row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TextView senderIDTextView = new TextView(Transactions.this);
senderIDTextView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
senderIDTextView.setId(100);
senderIDTextView.setPadding(10, 10, 10, 10);
senderIDTextView.setTextColor(Color.BLACK);
senderIDTextView.setBackgroundColor(Color.RED);
senderIDTextView.setText(senderID);
row.addView(senderIDTextView);
transactions_table.addView(row , new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
catch(Exception ex)
{
Toast.makeText(getBaseContext(), ex.toString(), Toast.LENGTH_LONG).show();
}
}
}
}
}
答案 0 :(得分:0)
您使用了原生布局参数作为操作栏,而不是使用它来使用tablerow的layoutparams。
<强>解决方案强>
将导入更改为
android.widget.TableRow.LayoutParams