[英]How to place button at the bottom of LinearLayout within a ScrollView
[英]handling LinearLayout within a ScrollView
最初,我具有LinearLayout> ScrollView> TableLayout和以下代碼:
LinearLayout layout = (LinearLayout) View.inflate(this, R.layout.photos_layout, null);
setContentView(layout);
// TODO Auto-generated method stub
//get the tableLayout which we created in main.xml
tl = (TableLayout)findViewById(R.id.tableLayout1);
for(int i = 0; i < names.length; i++) {
//Create a new row to be added.
TableRow tr = new TableRow(this);
//Create text views to be added to the row.
TextView tv1 = new TextView(this);
TextView tv2 = new TextView(this);
//Put the data into the text view by passing it to a user defined function createView()
createView(tr, tv1, Integer.toString(i+1));
createView(tr, tv2, names[i]);
//Add the new row to our tableLayout tl
tl.addView(tr);
}
問題在於,scrollView只能有一個孩子,因此,除了tableLayout之外,如果我想添加更多視圖,就不能。 為了克服這個問題,我制作了類似LinearLayout> ScrollView> linearLayout> tableLayout的層次結構。 但是,現在上面的代碼使應用程序崩潰。
為了填充表格以及向新創建的linearlayout添加視圖,我需要更改什么?
我建議刪除父LinearLayout。 Scrollview本身可以是父級,然后可以將一個LinearLayout作為其唯一的直接子級。
在您提到的發布的代碼崩潰時,您沒有在“新創建的” LinearLayout中添加任何視圖,而是在TableLayout中添加了新行,如果我猜對的話,它在滾動視圖中。 完全可以,並且不應該是崩潰的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.