PagerTabStrip和TabLayout之间的区别 [英] Difference between PagerTabStrip and TabLayout

查看:161
本文介绍了PagerTabStrip和TabLayout之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个我想添加标签的应用程序,以便可以将PagerTabStripTabLayout与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).

  1. TabLayout是活动/片段"的部分,在ViewPager之外,您可以将其附加到其中.它与页面分开滚动.
  2. PagerTabStripViewPager 的子元素.选项卡随页面滚动.
  1. A TabLayout is part of the Activity/Fragment, outside of the ViewPager, and you instead attach it to one. It scrolls separately from the pages.
  2. A PagerTabStrip is a child element of the ViewPager. The tabs scroll with the page.

这篇关于PagerTabStrip和TabLayout之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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