谷歌的Andr​​oid滑动标签布局布局、标签、Andr、oid

2023-09-03 21:34:59 作者:兜 兜、

我已经成功地使用谷歌的滑动标签code在我的项目。 (示例项目可以在这里找到: http://developer.android.com/samples/SlidingTabsBasic /index.html )这是我到目前为止有:

I have successfully used Google's Sliding Tabs code in my project. (Sample project can be found here: http://developer.android.com/samples/SlidingTabsBasic/index.html) This is what I have so far:

不幸的是,我无法弄清楚如何使标签占据整个酒吧。如下所示,它们占用了仅约一半的屏幕。我认为改变填充,但我不希望到c很难$ C $,因为不同的屏幕尺寸。我的最终目标是模拟的标签布局YouTube使用:

Unfortunately, I am unable to figure out how to make the tabs take up the entire bar. As shown below, they are taking up only approximately half the screen. I considered changing the padding, but I don't want to hard code it because of varying screen sizes. My ultimate goal is to emulate the tab layout that YouTube uses:

推荐答案

您可能会发现在 setDistributeEvenly 如果您使用来自

You probably find the setDistributeEvenly method cannot be resolved if you use the sample code from

http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html

然后在 createDefaultTabView 您的 SlidingTabLayout 类的方法,在返回的TextView前添加以下行

Then in the createDefaultTabView method of your SlidingTabLayout class, add the following line before returning the textView

textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f));