Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android using viewPager vs using tabhost

Tags:

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!

like image 759
Vijitha Avatar asked Dec 09 '13 10:12

Vijitha


2 Answers

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.

like image 181
Dhaval Avatar answered Sep 20 '22 16:09

Dhaval


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

like image 23
thanhbinh84 Avatar answered Sep 20 '22 16:09

thanhbinh84