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

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

问题描述

我正在开发一个应用程序,我想在其中添加选项卡,以便可以使用 PagerTabStripTabLayout 和 ViewPager 添加.

在我看来没有区别,但我想它们之间存在一些差异,因此它们是两个类.那么它们之间的主要区别是什么?

解决方案

只是比较视觉效果...

PagerTabStrip 更像是 ViewPager 当前页面的指示器,它旨在用作 ViewPager 小部件的子视图".它的滚动不像 TabLayout,因为每个选项卡都是页面的一部分,而不是单独水平滚动.

总而言之,区别在于(除了视觉效果).

  1. TabLayoutActivity/Fragment 的一部分,位于 ViewPager 之外,您可以将其附加到其中一个.它与页面分开滚动.
  2. PagerTabStripViewPager子元素.选项卡随页面滚动.

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).

  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天全站免登陆