PagerTabStrip 和 TabLayout 的区别 [英] Difference between PagerTabStrip and TabLayout
问题描述
我正在开发一个应用程序,我想在其中添加选项卡,以便可以使用 PagerTabStrip
和 TabLayout
和 ViewPager 添加.
在我看来没有区别,但我想它们之间存在一些差异,因此它们是两个类.那么它们之间的主要区别是什么?
只是比较视觉效果...
PagerTabStrip
更像是 ViewPager 当前页面的指示器,它旨在用作 ViewPager 小部件的子视图".它的滚动不像 TabLayout
,因为每个选项卡都是页面的一部分,而不是单独水平滚动.
总而言之,区别在于(除了视觉效果).
TabLayout
是 Activity/Fragment 的一部分,位于ViewPager
之外,您可以将其附加到其中一个.它与页面分开滚动.PagerTabStrip
是ViewPager
的子元素.选项卡随页面滚动.
I am working on an app where I want to add tabs so that can be added using PagerTabStrip
and TabLayout
with ViewPager.
It looks same to me with no difference but I guess there is some difference between them so they are two classes for this. So what is the main difference between them?
Just comparing the visuals...
TabLayout
is a material concept that replaced the deprecated ActionBar tabs in Android 5.0.
It extends HorizontalScrollView
, so you can keep adding tabs horizontally which can include text, icons, or custom views and scroll through them linearly without paging.
TabLayout
provides the setupWithViewPager(ViewPager viewPager)
method to attach to a ViewPager
instead of being part of the ViewPager
like the PagerTabStrip
.
A PagerTabStrip
is more of an indictor for the current page of a ViewPager, and "it is intended to be used as a child view of a ViewPager widget". The scrolling for it does not act like the TabLayout
since each tab is part of the page instead of individually horizontally scrollable.
In summary, the differences are (apart from visuals).
- A
TabLayout
is part of the Activity/Fragment, outside of theViewPager
, and you instead attach it to one. It scrolls separately from the pages. - A
PagerTabStrip
is a child element of theViewPager
. The tabs scroll with the page.
这篇关于PagerTabStrip 和 TabLayout 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!