作者:酷的带_201 | 来源:互联网 | 2023-05-17 21:03
Withmyslidingtabsproject,howcanIprogrammaticallysetthewidthofthetabssothattheyuse
With my sliding tabs project, how can I programmatically set the width of the tabs so that they use the whole space of the sliding tab strip and are each equal in width size? I've tried using the code below but the tabs won't stretch as desired.
使用我的滑动选项卡项目,如何以编程方式设置选项卡的宽度,以便它们使用滑动标签条的整个空间并且每个宽度大小相等?我已尝试使用下面的代码,但标签不会按要求拉伸。
SlidingTabLayout.java
SlidingTabLayout.java
protected TextView createDefaultTabView(Context context) {
TextView textView = new TextView(context);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setTextColor(context.getResources().getColor(R.color.black));
textView.setWidth(0);
int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
textView.setPadding(padding, padding, padding, padding);
return textView;
}
Text weight error
文字重量错误
3 个解决方案