2013-05-08 52 views
0

我有2個表格佈局。我想隱藏第二個佈局並將第三個佈局移動到第二個位置。如何設置tablelayout android:layout_below編程式

IM隱藏的第二個佈局,但不知道如何將第三佈局移動到第二位置

  TableLayout i=(TableLayout)findViewById(R.id.table2); 
    TableLayout i2=(TableLayout)findViewById(R.id.table3); 
    TableLayout i3=(TableLayout)findViewById(R.id.table4); 
    i.setVisibility(View.GONE); 
    i2.setVisibility(View.GONE); 
    i3.setVisibility(View.GONE); 
    TableLayout i5=(TableLayout)findViewById(R.id.table5); 
      i5.// Now i want to add this layout below to table layout R.id.table1 (the first table layout in this section)     

回答

0

表格的佈局則當u想使用view.addView(id)

+0

謝謝... m困惑於addview(id)。我試圖但htere是沒有這樣的方法/參數如下相對佈局。 – kunwarandroid 2013-05-08 07:40:32

+0

請發佈我們的整個代碼 – d3m0li5h3r 2013-05-08 07:46:13

0

嘗試設置

使用 view.removeView(id)
i2.setVisibility(View.INVISIBLE); 
+0

我已經完成了那部分薩加。我問,我想將最後的表格佈局移動到隱藏的佈局位置。 – kunwarandroid 2013-05-08 07:43:28

+0

所以你想隱藏i,i2,i3並把i5帶到自己的位置。 – 2013-05-08 07:46:48

+0

是的,現在你明白了 – kunwarandroid 2013-05-08 07:54:22

0

你可以這樣做,就像你說的你正在使用RelativeLayout一樣,所以創建一個垂直方向的子LinearLayout, n添加您要添加​​的所有表格佈局。

弓,如果你想在運行時在第一位置添加一個tableLayout,然後執行:

linearLayout.removeAllViews();

然後添加所需的TableLayout(這裏,I5),之後加入剩餘的佈局。

編輯:您的代碼:

TableLayout i=(TableLayout)findViewById(R.id.table2); 
TableLayout i2=(TableLayout)findViewById(R.id.table3); 
TableLayout i3=(TableLayout)findViewById(R.id.table4); 
i.setVisibility(View.GONE); 
i2.setVisibility(View.GONE); 
i3.setVisibility(View.GONE); 
TableLayout i5=(TableLayout)findViewById(R.id.table5); 
     i5.// Now i want to add this layout below to table layout R.id.table1 (the first table layout in this section) 

你要正確的,因爲我認爲你的代碼應該是這樣的:

TableLayout i=(TableLayout)findViewById(R.id.table1); 
TableLayout i2=(TableLayout)findViewById(R.id.table2); 
TableLayout i3=(TableLayout)findViewById(R.id.table3); 
i.setVisibility(View.GONE); 
i2.setVisibility(View.GONE); 
i3.setVisibility(View.GONE); 
TableLayout i5=(TableLayout)findViewById(R.id.table5); 
     i5.// Now i want to add this layout below to table layout R.id.table1 (the first table layout in this section) 

我認爲這是因爲你的註釋部分的i5後在上面碼。

相關問題