problem with viewpager2 and bottomnav working together in android studio - android

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

Related

Too many Fragments causing OutOfMemory error

I'm making an app that uses a bottom navigation bar (BottomBar) on its MainActivity. A FrameLayout is positioned above the BottomBar. Every time an icon in the bottom bar is clicked, the tab's fragment is inserted into the FrameLayout using FragmentTransaction's replace() function. That inserted fragment contains ViewPager, which results in more fragment launching and caching. Right now, there is only one Activity but many Fragments. I haven't load any data and I'm already receiving a OutOfMemory Exception even after setting the maxHeapSize to 4gb.
What can I do to improve the performance without changing the UI (still have a bottom navigation bar and each tab contains a viewpager)?

switching between fragments delete the views in first fragment

I have in my app a drawer navigation, which contain few fragments to go to. when my app starts it opens by default the first fragment - which contains a view pager that has 2 fragments in it as well. in those 2 fragments I have a text view and a button as well.
the problem is that if I click on another fragment in the drawer, and then go back to the first fragment, the button and the text view are gone. in the first time this view pager fragment is creating the two other fragments. I think that when I go back to this fragment again by replacing it, it wont load the other two fragments and their text and button view. I'm going crazy because of this and I cant continue my work..what is wrong here?
I don't know how to upload code snippets..sorry
Thank you for your help :)

Move the Floating Action Button along with the swiped tab

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.

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.

android listfragment + swiping through items

I'm developing an app, which consist of:
1. main activity, which has action bar, list fragment and some buttons at bottom
2. when you click on some item, another activity is launched - some buttons at top and webview under it.
I have everything working, but now I have to implement swiping between items from list, and I cant figure out how to swipe between activities. I though of changing items into fragments but then I have no idea, how layout should be worked out. I've read blog about viewpager, but as I understood, you can swipe only between 5 tabs with it, and I have 20+ items in listfragment. any ideas? thanks
create one Activity with ViewPager as it's main control. change items into fragments and add them to the ViewPager via FragmentAdapter
You can go ahead and user viewpager. there is no arbitrary limit to the number of pages.
It would be the quickest solution for you and seems to cover what you are doing.

Categories

Resources