Android using viewPager vs using tabhost
Asked Answered
M

2

22

In my Android application I have had to use a tab layout and I want to choose a one from folowing scenarios. they are

  • using viewPager
  • using tab host

what are the advantages of viewPager over tabhost. Which one is better. And I'm targeting the android 4.2. Thank You!

Morrismorrison answered 9/12, 2013 at 10:55 Comment(0)
A
6

It actually depends on what you want and the type of content you are putting in application.

ViewPager:

It is supported in lower API with support library and Sherlock library is always there. Using ViewPager will give a fresh and distinctive feel to the app. For this you'll need to use fragments. Which are complicated but great in terms of performance and are replacable(a superb feature).

ViewPager

TabHost:

This is achievable using both Fragments and Activities. Although in favour of FragmentTabHost, TabActivity has been deprecated. However if you are not experienced with Fragments, use Activities, but you can always migrate to fragments later. FragmentTabHost

You should check out different tutorials and implement both of them, then decide. You should learn fragments if you embark on using ViewPager. For which, Check this

This blog has numerous examples of tabs. It can help you decide.

Antecede answered 9/12, 2013 at 11:16 Comment(2)
You are spreading rumours! Tabhost is not deprecated. see this: https://mcmap.net/q/658314/-android-tabhost-deprecated I am using it since I need tabs inside my FragmentRaquelraquela
I'ved edited the answer. I know TabHost isn't deprecated. I use it as well. Seems i typed my answer incorrectly back when i posted it. Thanks for correction.Antecede
H
1

I found it very painful to customize tab host such as increasing indicator height, have to create 9 draw batch and customize background and many things.

With tab layout, only one line of code https://developer.android.com/reference/android/support/design/widget/TabLayout.html#setSelectedTabIndicatorHeight(int)

So, I recommend using view pager with tab layout that provides the same UX. Tab host is not deprecated, but it will happen soon, I guess :P

Hennery answered 15/8, 2017 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.