简体   繁体   English

如何以编程方式设置tablelayout android:layout_below

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

I have 2 table layout .我有 2 个表格布局。 I want to hide the second layout and move the third layout to second position.我想隐藏第二个布局并将第三个布局移动到第二个位置。

I'm hiding the the second layout and but don't know how to move the third layout to second position我隐藏了第二个布局,但不知道如何将第三个布局移动到第二个位置

            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);

You can do it like, as you said you are using RelativeLayout, so make a child LinearLayout with vertical orientation, then add all the table layouts you want to add.你可以这样做,就像你说你使用的是RelativeLayout,所以创建一个垂直方向的子LinearLayout,然后添加你想要添加的所有表格布局。

Bow if you want to add a tableLayout at runtime at the first position, then do:如果您想在运行时在第一个位置添加 tableLayout,请鞠躬,请执行以下操作:

linearLayout.removeAllViews();

Then add the required TableLayout(here, i5) and after that add the remaining Layouts.然后添加所需的 TableLayout(here, i5),然后添加剩余的布局。

Edit: Your code:编辑:您的代码:

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)  

Are you going right, as i think your code should look like:你走对了,因为我认为你的代码应该是这样的:

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)  

I suggested this because of your comment section after i5 in your above code.我建议这样做是因为您在上面的代码中i5之后的评论部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM