fragment partial replacement - android

i have 2 fragments with their respective layout. when someone open the application fragment 1 should appear. fragment1 have a button. when the user clicks that button , the fragment1 should slide right partially i.e 80% and at that place 2nd fragment should appear. 20% of the fragment 1 should still be visible. when the user again click that button, the fragment 2 should completely slide to left and and fragment 1 must be visible completely now. please tell me how i can do this.
thanks in advance.

Related

When I replace a fragment the scroll is not to the top

I have an frame in an activity which received fragments based on button clicks at the bottom menu of the activity.
The Fragment I I have in question is structured like below. If I click off of the fragment when i'm at the scrolltop to another and then back to this one it stays at the top but if I scroll 1/2 way down the fragment and then leave and come back it is like 10% scrolled from the top. an odd behavior i'm not sure how to rectify.
Main Activity ->>viewpager1(frameLayout)->fragment1->frag1_constraint(ScrollView)
Fragment 1 Layout
Main Activity Layout

How are transaction between two fragment in BottomNavigationView in Apps like YouTube so smooth?

I am making an application that has MainActivity that contains BottomNavigationView and FrameLayout above it. There are 3 Fragments say Fragment A, B, and C.
My doubt is, How do I make switching of Fragments as quick as YouTube Android application? By saying quick, I mean that, when I am on "Home" tab of Youtube application and I switch to the "Trending" tab and again go back to the "Home" tab, it simply loads "Home" tab within fraction of seconds, as if it just hided the inflated page in background and showed up when selected from BottomNavigationView. And also, It inflates the page exactly to the same position where I left.
When I am trying to implement the same in my Application, the RecyclerView in Fragment A re-inflates if I come back from Fragment B.
I am expecting the idea how they do it and in which method they do it (For eg. onStart or onDestroy or onViewCreated)...
If you are using viewpager then Increase the viewpager offset limit
viewpager.OffscreenPageLimit = 2;
Tt's limit is one by default. I hope this may fix your issue.
Thanks

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 :)

android with viewpager When i click on Button in the first fragment I want the app to navigate to another activity

I have two fragments implemented using View Pager. In fragment 1 I have 2 button and in fragment 2 I have list of item.
When I click on particular button in the first fragment I want the app to navigate to another activity.
but this scenario when I click on particular button in the first fragment then It's click on Second fragment list item and open list item detail.
If anybody knows, please suggest me a solution. I need to do this as soon as possible.
Thanks
One thing that came on top of my head is this:
Store your fragments in a ViewPager.
Listen to button click events in your first fragment.
From your first fragment, notify your activity of said click event.
Your activity (which also houses the ViewPager) should respond to the click event by commanding the ViewPager to move to the second page (which also contains your second fragment). You can do this by calling yourViewPager.setCurrentItem().
And there you have it. A fragment that contains button which move the pager onto the next page/fragment.

Fragment Animation and stop at a particular level android

I am using fragments in my application. I am at fragment A and I click on a button in Fragment A. That time I want my Fragment B to appear with an animation . Fragment B has to appear from the Bottom and stop at the center of the screen.
So now I can see my Fragment A at the top and Fragment B at the bottom. How can I achieve this?

Categories

Resources