Java Android:TabLayout如何通过编程设置高度=0?
以下是我的表格布局xml: 如何更改TabLayout.android:layout\u height=0编程设置。?试试这个 对于约束布局,您必须简单地更改高度和宽度Java Android:TabLayout如何通过编程设置高度=0?,java,android,android-tablayout,Java,Android,Android Tablayout,以下是我的表格布局xml: 如何更改TabLayout.android:layout\u height=0编程设置。?试试这个 对于约束布局,您必须简单地更改高度和宽度 tabLayout=(TabLayout)findViewById(R.id.tabLayout); ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) tabLayout.getLayoutParams(); // Ch
tabLayout=(TabLayout)findViewById(R.id.tabLayout);
ConstraintLayout.LayoutParams params =
(ConstraintLayout.LayoutParams) tabLayout.getLayoutParams();
// Changes the height and width to the specified *pixels*
params.height = 500;
params.width = 500;
tabLayout.setLayoutParams(params);
输出
高度不变。@Alexei请尝试,我还粘贴了studio预览和我设备的输出。无帮助。高度是不变的。ConstraintLayout.LayoutParams params=ConstraintLayout.LayoutParams tabLayout.getLayoutParams;参数高度=0;tabLayout.setlayoutparams;将参数设置为高度=1;而不是params.height=0;对这是工作!!!问题是:为什么height=0不起作用,而height=1起作用?我如何通过编程更改TabLayout.android:layout\u height=0?为什么不改为执行tablayout.setVisibilityView.GONE?因为我需要显示选项卡,但通过将tablayout的高度设为0dp隐藏标题,您将不再看到tablayout或选项卡。那么,您打算如何显示选项卡?
tabLayout=(TabLayout)findViewById(R.id.tabLayout);
ConstraintLayout.LayoutParams params =
(ConstraintLayout.LayoutParams) tabLayout.getLayoutParams();
// Changes the height and width to the specified *pixels*
params.height = 500;
params.width = 500;
tabLayout.setLayoutParams(params);