我使用谷歌的SlidingTabLayout。因为我只需要显示3个标签,我看到最后一个选项卡后,空的空间。 请下面的截图。
I am using Google's SlidingTabLayout. As i only have 3 tabs to be displayed, I am seeing empty space after last tab. Please screenshot below.
有人能解释我如何适应标签以整个屏幕。感谢您的时间。
Can someone explain me how to fit the tabs to entire screen. Thanks for your time.
在 SlidingTabLayout.java
,找到
protected TextView createDefaultTabView(Context context)
和这些行添加到该方法:
and add these lines to that method:
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
textView.setWidth(size.x / 3);
这是固定的,对我来说。基本上,你让你的屏幕分割的宽度由3(标签数),并设置了作为宽度文本字段
,使你的标签。
That fixed it for me. Basically, you're getting the width of your screen and dividing by 3 (the number of tabs) and setting that as the width for the TextField
that makes up your tab.
更新:
在电流源,谷歌增加了一个 setDistributeEvenly(布尔);
的方法,这样你就可以使用 slidingTabs.setDistributeEvenly(真);
代替。当使用旧的源$ C $ C,可以使用我的解决方案上面,或更新到最新的源(后者推荐)。
In the current source, google added a setDistributeEvenly(Boolean);
method, so you can use slidingTabs.setDistributeEvenly(true);
instead. When using the older source code, either use my solution above, or update to the newest source (latter is recommended).