Search code examples
androidandroid-fragmentsandroid-viewpagerandroid-tablayoutfragment-tab-host

Overlay a Fragment over existing Fragment


I have a design of TabLayout or TabHost which ever you want to consider. Suppose this are the tabs -

Tab1 | Tab2 | Tab3 | Tab4 | Tab5

In this following action will take place -

  1. Tab1 - opens Fragment1
  2. Tab2 - opens Fragment2
  3. Tab3 - opens an overlay over existing fragment with a translucent black view
  4. Tab4 - opens Fragment3
  5. Tab5 - opens Fragment4

Any idea about how to solve this? Thanks in advance!!

UPDATE: Solution I used

I tried this, but had to make lot of customization. So I stopped in middle as it was hell lot of work. So another way around I did is I put one more view over the TabLayout on exactly same position as of Tab3 and on click of that View I made the overlay view visible.


Solution

  • ViewPager is not designed for this use case. Tabs automatically map to their corresponding element in the ViewPager. But here's how I could see it kind of working.

    1. Have a TranslucentOverlayView that has Visibility.GONE which overlays your entire ViewPager.
    2. Have tab3 open a duplicate clone of fragment2, and when tab3 is selected, make the TranslucentOverlayView visible. This does mean that you'll have two separate instances of fragment2 side by side though.