Move the Floating Action Button along with the swiped tab - android

Let me brief about my idea and what I'm aiming to achieve,
Idea is to have a swipe tab with three tabs in it and each tab screen being represented by a seperate Fragment class. I did this using the "it.neokree:MaterialTabs:0.11" library and everything is working well.
Then I created a floating action button (FAB) using the "com.oguzdev:CircularFloatingActionMenu:1.0.2" library.
Now what I'm trying to achieve is to fix this FAB to the fragment in the center tab and when I swipe the screen to go the previous or the next tab the FAB should slide out along with the tab fragment its in and should slide back in along with the center tab screen when I swipe back to it.
I have worked on it till now and now I'm able hide the view in other fragments and show it again in the center fragment by overriding the setUserVisibleHint() method in each fragment class like this.
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
View tempView = getActivity().findViewById(R.id.myFAB);
tempView.setVisibility(View.INVISIBLE);
}
}
But the problem is I want the FAB to slide out and in along with the center tab just like other views in the tab's fragment class does, but my FAB is simply vanishing and reappearring.
In a way I want the FAB to be exclusive to the center tab and should be fixed to it.
I also tried defining the FAB inside the center Fragment class but it doesn't seem to make any difference. Any Advice and suggestion will be very helpful. Thanks in advance

This library adds it's view to the 'android.R.id.content' ViewGroup. That's why it doesn't matter, where you define it.
Animating such view may be difficult, but should be possible. You have translate the FAB while swiping the pager manually.
By the way, Google recommends to hide the FAB, not swipe:
For tabbed screens, the floating action button should not exit the
screen in the same direction as the screen exits. Doing so creates
visual noise. It would also cause a nonfunctional floating action
button to appear on screen. Furthermore, it incorrectly implies that
the floating action button is at the same the z-level as the content,
rather than at the level of the primary UI elements at the root
level.
See: http://www.google.com/design/spec/components/buttons-floating-action-button.html#buttons-floating-action-button-behavior

If you want to show the FloatingActionButton only in the middle/single tab, then you can add the FAB in the Fragment instead of adding it in Activity in which all the Fragments are added.

Related

problem with viewpager2 and bottomnav working together in android studio

so I'm trying to make small application type of thing where it has bottom navigation bar and viewpager2 working in it. But I want it so that in the first fragment page that application loads in, only there viewpager2 is available to work and be able to swipe, when I switch to next fragment with navigation bar that viewpager2 should basically disappear and not work, therefore my logic was to put that viewpager2 in that single fragment and navigation bar outside in main activity for it to be able to be seen in every fragment. But there is a problem, it almost works, I switch to another fragment with bar view pager disappears but when I go back to that first fragment view pager is just gone, disappeared and I have no idea what's the problem. if necessary I can show what I have written. Thanks in advance

Programmatically scroll FAB back in

I am using coordinator layout with tabs, some of which (the tabs) contain a recycler view whilst some don't. All the tabs contain a floating action button. On scrolling the recycler view with the in one of the tabs, the floating action button is scrolled off by the coordinator layout. However, when I switch to the tab without the recycler view, and not being able to scroll, the tab remains scrolled off the screen (as it was done in the tab with a recycler).
How do I bring back the floating action button back when there is no way of scrolling in the tab without the recycler or any scroll mechanism?
Turned out to be a simply solution of translating the fab back in. floatingActionButton.setTranslationY(0.0f);

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

Swiping in order to call another Activity in Android

I want to make something like transitions between ViewControllers in iOS 7 but in Android, is it possible?
Explanation: please look at image below, I have main Activity which has ViewPager inside, so we can swipe between Fragments. I want to call another Activity (or Fragment) from each Fragment (blue on image) swiping to bottom or to top but this action should be done smoothly like in ViewPager.
You can intercept swipe up and down gestures and set items in viewpager accordingly. Please read this guide on how to intercept swipes in various directions.

Sliding the top layer of an activity when clicking a button

Please, suggest a solution for the following scenario:
When a user clicks a button, the screen must be slid from right to
left and the next screen must be shown. But the background for the
both screens is the same (it's an image), and it is not slid, it stays
at its place.
What can you suggest? Can I use activities here, or there must be fragments, or anything else?
I found the solution. I created an activity and in the setContentView() function set a layout with a custom ViewPager. In the custom ViewPager the onTouchEvent() and onInterceptTouchEvent() functions are overriden and just return false.
The screens are implemented as Fragments. When a button is clicked, the viewPager's setCurrentItem() function is called and the corresponding screen is shown (the viewPager object is declared static and it can be called from a fragment).
Here is a good example of using ViewPager: http://www.javacodegeeks.com/2013/04/android-tutorial-using-the-viewpager.html
And this is an example of a custom view pager, where sliding is disabled: https://stackoverflow.com/a/13437997/2346046

Categories

Resources