Move top navigation bar along with the screen - android

I think the way I was going is wrong. I wanted to create a top navigation bar which has 3 items so I created tabs and with a View Pager, I used 3 fragments for each tab. That way I can slide screens between each other, but the tabs are not moving along with the screen.
Can someone suggest me how to make top navigation bar items moving along with the screen is sliding?
This video explains exactly what I want. Please note how the top bar items are moving along with the screen.
https://drive.google.com/file/d/1OzDFR4VT_YyDumEZLOWtGZ-_5BLXAfK4/view

Related

AppBar with Fragments and Bottom Navigation Bar

Not sure if I'm fighting an uphill battle but I'm currently struggling with AppBar, Fragments and Bottom Navigation Bars.
I have a MainActivity that's a list view with an AppBar. It's created as a fragment with the intention to add another bottom navigation bar here in the future.
For now, when an item in the list is clicked it navigates to a detail view fragment. Here I still have the AppBar which is what I want however I would like to add a Bottom Navigation Bar. However when I navigate to the next fragment I lose my bottom navigation bar.
Is there a way to keep maintain Bottom Navigation Bars within Fragments? I tried breaking them out into activities but discovered then I lose my AppBar.
Is what I'm doing above feasible in Android?
Ideally I'd like this:
Do you have different nav graphs for different fragments? You need to have the detail view fragment in the same nav graph as the bottom navigation view. You don't need to have another item in bottom navigation but declare fragments that you want with bottom navigation in the same nav graph.

BottomNavigationView that opens detail in full screen

I'd like to build an app that has what I understand top be a three top level screen hierarchy like this:
That is, Master screen displays different sections with different content, comprised of items that can be articles (green) or videos (blue).
Clicking on an article (in any of the sections) would take you to a detail screen (top right, in yellow) that should maximize reading area, with a topbar with a back/close button, and covering the bottomnavigationview. Going back (or up) takes you again to the screen with bottomnavigationview.
Clicking on a video would launch a different detail page in which the video can be dragged to the bottom as shown in bottom left screen, so you can still operate with the master list of items (or whatever lies beneath).
Either clicking on an article item (green), or clicking on a video item on top right (detail of an article), would take you to what is shown on bottom right; that is, video detail over article detail. Video then can be dragged to reveal underlying article and still be operable.
Now I already have a fragment that implements the dragging behavior of a video detail, that is not an issue.
My problem comes with understanding how to architect this with Navigation Component. My naivest approach would be ditching the nav component and have on my activity three fragment holders, one for the bottomnav content, one for the article detail, one for the video detail (which has to be above everything else), but getting rid of the nav component means i have to implement such things as backstack and deep linking myself.
Is this kind of navigation flow possible with navigation component? If anything, I'd like at least to get the master-article detail implemented with NavComponent, and separate the video implementation in a differnet fragment holder.

Getting the width of an action bar tab

I want to have an action bar with tabs and a viewPager for the body in order to be able to scroll the tabs.
I also want to have a view to "underline" the selected tab, and have it move when I scroll the viewPager.
Is there a way to get the size of the tab? Since I'm different devices the tabs may be scrollable I can't just divide the size of the screen by the amount of tabs..
I want it to be something like this:

How to implement vertically moving tabbs panel?

In google play, if you enter a screen that uses tabs, you can notice how you can scroll each tab but the panel that seen to contain the tabs also moves vertically to a certain extent. I can imagine that it accomplishes the movement of the tab panel with a TranslateAnimation and a layout animations. But what I can't understand is how it decouples the content of the tab from the tab panel.
To answer the decoupling of the tabs and content question; I have implemented this before using 2 sets of tabs. One is in the content as a list header, the other is layered on top of the list in a containing FrameLayout so it's 'floating'.
Using scroll callbacks you can change the visibility of the floating tabs to suit your needs. Once the list header tabs moves off the screen make the floating tabs visible, once they move fully back onto the screen hide the floating tabs.
Just ensure that every time you show/hide tabs that you copy the values for horizontal scroll position and selected tab from the currently visible tabs to the ones that are about to become visible. works a treat.
The best open-source project you can find for this Android-ObservableScrollView

Swipe tabs inside one specific fragment

Inside my app I am using navigation drawer for my navigation. For each "page" I am using fragments (like showed here: http://developer.android.com/training/implementing-navigation/nav-drawer.html). It works completely fine, but now I want to create swipe tabs. I want to display those tabs only on one of the fragments. Problem is, that tabs are displayed on all fragments, which is ofcourse perfectly normal because tabs are inside action bar. What should I do, to display tabs only on one fragment?
From what I have understood, you are interested in showing action bar only in a particular fragment (not visible when swiping in subsequent fragments). The best way would be to code the action bar in fragment instead of using the action bar in main fragment and then creating swipe views (or sub fragments).
Hope it helps.

Categories

Resources