在此page Google 明确表示 TabLayout 可以在布局 xml 文件中集成到 ViewPager 中。
ViewPager integration
If you're using a ViewPager together with this layout, you can call setupWithViewPager(ViewPager) to link the two together. This layout will be automatically populated from the PagerAdapter's page titles.
This view also supports being used as part of a ViewPager's decor, and can be added directly to the ViewPager in a layout resource file like so:
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</android.support.v4.view.ViewPager>
但是,无论我怎样尝试,我都无法让 TableLayout 出现。两者分开就好了。我想知道这真的有效吗??
最佳答案
我不认为 TabLayout
像他们声称的那样作为 ViewPager
子项工作。
任何想要成为 ViewPager
subview 的 View 都必须设置一个特定于 ViewPager
的 bool 布局参数属性,称为 isDecor
。我刚刚查看了源代码,但没有看到 ViewPager
或 TabLayout
设置此布局参数属性的任何地方。
我认为这是他们打算做的事情,要么 a) 他们从未这样做过,要么 b) 出现问题所以他们将其删除。只需在 ViewPager 外部使用 TabLayout,将其作为装饰 View 并没有真正的好处。
关于android - ViewPager 内的 TabLayout 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38614184/