Animate Tabs in TabLayout - android

To be specific I want to animate the tabs and not the ViewPager fragments.
I am having trouble deciding how to build this. Whether to use a separate scrollview or this can be achieved with TabLayout with some customizations.
Goal
Change the size of tab based on selection.
Change the size of tab based on position.
My idea is to use custom tabs & change the size using TabLayout.OnTabSelectedListener methods onTabSelected & onTabUnselected. But I would like to know if there is any direct approach to get this effect. For example, parallax effect in CollapsingToolbar.

Related

Difference between Tab Layout and ViewPager?

I'm learning about tab layout because I need to use tab layout.
When i search for tab layout on Google, the one that comes up together is the view pager.
By the way, I'm not sure about the difference between tablayout and viewpager.
The tab layout has a menu at the top and screen switching is possible.
Although the view pager does not have tabs, it is possible to slide the screen just like the tab layout.
But why use the two together?
What's different?
Isn't it possible to slide in tab layout as well?
Yes, you can use TabLayout without viewPager. But without viewpager you won't be able to slide your page. You have to handle tabselect listener manually using this method then you have to click on the tab to navigate.
addOnTabSelectedListener(OnTabSelectedListener)
Likewise, you can use only Viewpager then you will be able to slide or swipe your page without any tabs.
From official doc
TabLayout
TabLayout provides a horizontal layout to display tabs.
Viewpager
Layout manager that allows the user to flip left and right through pages of data.
So Tablayout and viewpager are two different things but you can have the privilege of both tabs and slide only by combining them.
You can check here for tablaout without viewPager
TabLayout without using ViewPager

TabLayout versus pagerTabStrip for convenience and functionality

When using a ViewPager, is there any advantage to using TabLayout instead of PagerTabStrip or vice versa? Or are they equivalent? Is one more convenient than the other? Does one offer greater functionality? Again all questions are asked, and thus all answers are expected, in the context of ViewPager. Thanks.
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.

ViewPager in Fragment - Setup tabs

I'm familiar with nested fragments. I am using viewpager in a fragment. I have three tabs, and want them to fill width. Instead of actionbar tabs, I tried using
SlidingTabLayout, but it doesn't fill width.
PagerTabStrip but the look doesn't suit my requirements
TabHost is too naive.
I'm ok to write my own tab layout if necessary but as it is heavily used, I don't think that is actually necessary. Please help me in this regard

PagerTabStrip customization - moving tab background instead of standard indicator

I am trying to use PagerTabStrip in my app but need a little customization. My problem is that I want the tab background to be moved instead of the standard indicator. The image should explain it better:
Currently I don't show at all tab indicator, but use a tab background which is a selector (pressed & selected). This tab background behaves like a tab indicator but is jumpy and I would like to move it smoothly when sliding left/right.
I have have used the PagerTabStrip, got it to work and changed the height of the indicator to match the height of the tabbar but this didn't solve the problem because the indicator is drawn on top of the tabs and covers them. To solve the problem the indicator needs to be drawn behind the tabs. To do that I have modified PagerTabStrib and made a custom TabsContainer (by default LinearLayout is used in PagerTabStrip as a tabs container) an inner class which extends LinearLayout and overrides its onDraw() method where I want to draw the moving indicator. This way the indicator should be drawn behind the tabs, right? My problem with the code right now is that I don't get calls to onDraw() inside my custom TabsContainer. What do You think about this solution and about this problem? Do You see any better solution?
Thanks for any help.

Make ViewPager overlap PageTitleStrip

I've been struggling with that for a while: Is it possible to force PageTitleStrip draw itself on the content of the ViewPager?
Here is the case:
The red line indicates the end of ViewPager content and the start of PagerTitleStrip. The brown background belongs to the hole activity. Blackboard and blue backgrounds are from fragments in pager. The screen is taken during scrolling so that 2 fragments can be seen. I want the icons from PagerTitleStrip to be displayed transaprently and party on the viewPager's content.
Any suggestions are highly appreciated.
I don't think it's possible to do this with the built-in ViewPager and PagerTitleStrip. You will have to make your own custom component based on these to get the effect you're looking for.

Categories

Resources