SlidingTabLayout以适应屏幕 [英] SlidingTabLayout to fit the screen

查看:2387
本文介绍了SlidingTabLayout以适应屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌的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).

这篇关于SlidingTabLayout以适应屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆