PagerTabStrip和TabLayout之间的区别 [英] Difference between PagerTabStrip and TabLayout
问题描述
我正在开发一个我想添加标签的应用程序,以便可以将PagerTabStrip
和TabLayout
与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
是一个实质性概念,替换了Android 5.0中已弃用的 ActionBar选项卡.
它扩展了HorizontalScrollView
,因此您可以继续水平添加选项卡,其中可以包含文本,图标或自定义视图,并且可以线性滚动它们而无需分页.
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
提供 setupWithViewPager(ViewPager viewPager)
方法来附加到 ViewPager
,而不是像PagerTabStrip
那样成为的一部分.
TabLayout
provides the setupWithViewPager(ViewPager viewPager)
method to attach to a ViewPager
instead of being part of the ViewPager
like the PagerTabStrip
.
PagerTabStrip
更像是ViewPager当前页面的指示符,并且它旨在用作ViewPager小部件的子视图".由于每个选项卡都是页面的一部分,而不是单独地水平滚动,因此其滚动不像TabLayout
那样.
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).
-
TabLayout
是活动/片段"的部分,在ViewPager
之外,您可以将其附加到其中.它与页面分开滚动. -
PagerTabStrip
是ViewPager
的子元素.选项卡随页面滚动.
- 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屋!