Overlap a layout with viewPager - java

maybe you can help me. I want to use viewPager to overlap an other layout. so for example: I the first Fragment. On this Fragment is a picture, than I swipe to the right and then the second Fragment should just go over the first Fragment. It's like in the Android Youtube App in which you swipe from left to right and the settings and etc go over the main layout(like in the picture). Can you tell me what i have to do?
Thanks a lot, Vinzenz.
picture:
http://i.stack.imgur.com/CQ8gL.png

What you're asking for is actually not related to ViewPager. There is another layout you can use to implement the same navigation pane overlay: DrawerLayout link: http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html

Related

Is there a way to choice a specific one between fragments as extra data?

Now I am making a small android-app.
And I face a problem.
It is a structure of my app. The red arrow is a problem.
I can go to ConfigActivity, But now I only can go HomeFramgent not ConfigFragment.
How can it be possible?
Is there a way to choice a specific one between fragments in that arrow?
Sorry for my poor English. Give me some advice to solve this problem please. Thank you.
Hey You can switch to your fragments of HomeActivity which uses Tab layout like this:
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
TabLayout.Tab tab = tabLayout.getTabAt(someIndex);
tab.select();
You can keep the current fragment's sate, check it in onResume() method of MainActivity and go to the needed fragment (last opened).
Advice - use only fragments. Left only Main activity for the whole app.
Why you shouls use fragments instead of activities - https://medium.com/mobile-app-development-publication/activities-or-fragments-a-little-sharing-c1ddc1041f79

Make ViewPager swipable through external layout / from outside

In my application I have an activity thats layout is basicly following:
App layout
The red part is a viewpager with fragments.
The blue part is a layout with buttons that doesnt change with swipe on viewpager.
But i want that the viewpager is swipable (smoothly) in the hole green framed area. It should act like normal viewpager behavior.
I have absolutely no idea if that is even possible or not, but hope it does.
I thought that it is maybe possible with a gestureoverlay or something, but don't know how to apply the detected gesture on the viewpager.
Only detecting swipe and set current page is not what I want achieve.
(I'm writing in java)
If the height of the viewpager and buttons layout are somewhat fixed, here is a solution:
1, use a ConstraintLayout as the root container
2, make viewpager the same size as the root, set the viewpager's padding to some value say 8dp
3, place the buttons layout over the view pager, taking up the bottom half space(except for some margin), the viewpager should still respond to touch where there is no button
4, for fragments inside view pager, use a ConstraintLayout to put the content at the top half of the page
I think this is what you are looking for
Nested Action Bar Tabs(with ViewPager)
There's also a demo on Github: https://github.com/r3dm4n/NestedActionBarTabswithViewPagerDEMO
Let me know if it helped

What is the best way to create pages(about/my home/references tabs) as in the image below?

I just started learning Android programming. I've created a page and I want to create "About/My Home/References" tabs in the image below.
The "About/My Home/References" tabs (you can see them in the link below) all act like a button. When I click the "About" tab, I can see the things about the users. When I click the "My Home" tab, I can see the some text about my home. The third tab also does the same thing.
Image link: https://imgyukle.com/i/4LgQH
My question is how can I do this in Android Studio? I've added three button but it doesn't look like that. Any idea?
You can use TabLayout with TabItems widgets. Visit, for example, https://material.io/develop/android/components/tab-layout/ for short overview and https://www.codingdemos.com/android-tablayout-example-viewpager/ as step-by-step manual.
For that layout, you want to use Fragments and a ViewPager with a TabLayout.
Your main Activity would contain 3 Fragments, AboutFragment, HomeFragment and ReferencesFragment.
This would allow you to build each layout separately. The ViewPager would contain the Fragment, and lets you swipe between them. The TabLayout contains your buttons, to tell the ViewPager which to show.

How to re-use same fragment across viewPager

I have a fragment with a textView. I want the textView to change when I scroll across the viewPager.I want to reuse the same fragment rather than creating a new fragment for displaying each text.How do I do this? I hope pro developers can understand what I mean.
You cannot attach a same fragment into activity twice simultaneously. If you want the behavior you mentioned don't use ViewPager. Just use swipe gesture detection in a layout and maybe some animations.

Android - add Swipe View/tabs to only SOME fragments

Currently, my app is using a navigation drawer for my fragments. However, I have 2 fragments that are related, I would like to put these under one heading on the navigation drawer and then have 2 tabs to switch between the related fragments once I select that choice on the drawer.
Is this possible with only one activity or would I have to implement another activity specifically for the tab? I've considered only adding the tabs once the right fragment is committed but that leaves the question of how to remove it once I switch to a fragment that doesn't require the tabs.
I'd also like to avoid having to implement another activity as I am trying to keep the navigation available through my whole app. I'd rather not have to create an identical drawer and then have to keep things consistent between the 2 drawers.
Edit:
So far, I've managed to make a parent fragment that has a viewpager, fragmentpageradapter, and tablayout. Swiping between the 2 tabs does indeed shift between my 2 desired child fragments. However, I am unable to change a textview in one of my child fragments from my MainActivity. I'm guessing the reason why this is the case is because technically, my parent fragment is in view, not my child fragment. Any suggestions to get around this?
Hierarchy:
MainActivity
-Navigation Drawer
--Fragment1
--Fragment2
--Fragment3
--Fragment4
---FragmentPagerAdapter (under Fragment4, tabs)
----SubFrag1
----SubFrag2
Here's how you might use FragmentStatePagerAdapter to swipe across a Fragment:
http://developer.android.com/intl/es/training/implementing-navigation/lateral.html
I hope it help you.

Categories

Resources