簡體   English   中英

TableRow在單獨的行中有兩個TextView

[英]TableRow with two TextView in separate line

我有以下代碼:

TextView name = new TextView(this);
                          name.setText(venues.get(j).name);
                          name.setLayoutParams(new LayoutParams(
                                    LayoutParams.FILL_PARENT,
                                    LayoutParams.WRAP_CONTENT));

                          TextView address = new TextView(this);
                          address.setText(venues.get(j).getFullAddress());
                          address.setLayoutParams(new LayoutParams(
                                        LayoutParams.FILL_PARENT,
                                        LayoutParams.WRAP_CONTENT));
                          /* Add Button to row. */
                          tr.addView(name);
                          tr.addView(address);

現在,它給了我這樣的布局:

在此處輸入圖片說明

我希望TextView在單獨的行中。 我該怎么做呢?

首先,不要對要進入TableRow的View使用LayoutParams ...請使用TableRow.LayoutParams。

第二(請告訴我是否誤解了您的問題),如果您想讓您的編輯文本顯示在不同的行上……這意味着您希望它們在不同的行上顯示。 換句話說,不要將它們放入同一TableRow中。 您可以將它們放入單獨的TableRows或使用LinearLayout。

嘗試將addr添加到另一個TableRow

TextView name = new TextView(this);
TextView addr = new TextView(this);

name.setText("Name");
addr.setText("Addr");

TableRow tableRow1 = (TableRow) findViewById(R.id.tableRow1);
TableRow tableRow2 = (TableRow) findViewById(R.id.tableRow2);

tableRow1.addView(name);
tableRow2.addView(addr);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM