我想在我的应用程序显示的某些片段中隐藏我的Tablayout。一种解决方案是将TabLayout的android:aylout_height属性设置为eiher" 0dp"或" wrap_content"。但是如何以编程方式将高度设置为0dp? TabLayout甚至可以实现这一点吗?
答案 0 :(得分:2)
的xml:
android:visibility="gone"
代码:
TableLayout layout= (TableLayout ) view.findViewById(R.id.layout_table);// change id here
layout.setVisibility(View.GONE); //VIEW.VISIBLE etc.
答案 1 :(得分:2)
在您希望TabLayout
不显示...
tabLayout.setVisibility(View.GONE);
我会将您上面的代码部分放在片段的onCreateView()
方法中。
然后,在您希望它再次显示的片段中:
tabLayout.setVisibility(View.VISIBLE);