Is in whats app the floating action button part of each fragment (chats, status, calls and so on) or is the fab part of the enclosing main layout that encapsulates the fragments?
Because the fab does not scroll sideways away with the fragment contents i tend to the latter case but then again i just started android programming and know nothing about layout flags or options that might cause this behaviour...
Yes, the FloatingActionButton
(fab) seems to be a part of the Activity layout. The Activity likely has a ViewPager
beneath the TabLayout
- this is a pretty common approach to building these types of layouts. The ViewPager/TabLayout
combination is set up to link the pages as you either scroll or tap the tabs to Fragments
that each have their own logic and implementation associated with them. The fab sits at the Activity level so it is unaffected by the changing of pages. However the Fragments definitely modify the fab visually (you can see the icons change when you change pages) and logically so when the view is clicked it performs the correct action depending on the currently shown page.
Take a peak at this article to see a simple implementation to get your hands dirty with some of the code: https://medium.com/@Abdulkadir98/android-sliding-tabs-with-viewpager-851f9c996cb5