![](/img/trans.png)
[英]Can I Set "android:layout_below" at Runtime Programmatically?
[英]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.