簡體   English   中英

如何以編程方式設置tablelayout android:layout_below

[英]How to set the tablelayout android:layout_below programmatically

我有 2 個表格布局。 我想隱藏第二個布局並將第三個布局移動到第二個位置。

我隱藏了第二個布局,但不知道如何將第三個布局移動到第二個位置

            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)                 

使用表布局的view.removeView(id)然后當你想使用view.addView(id)

嘗試設置

i2.setVisibility(View.INVISIBLE);

你可以這樣做,就像你說你使用的是RelativeLayout,所以創建一個垂直方向的子LinearLayout,然后添加你想要添加的所有表格布局。

如果您想在運行時在第一個位置添加 tableLayout,請鞠躬,請執行以下操作:

linearLayout.removeAllViews();

然后添加所需的 TableLayout(here, 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之后的評論部分。

暫無
暫無

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

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