Image between fragments in a viewpager while swapping - java

Is there a way to add an image (ie. a arrow) between two fragments in a viewpager while swapping the fragments? By default the fragments are just stinking together and at least i want some extra space between the fragment cards.
Any ideas?
With best regards,
Juergen

Add Your View pager & Image in Frame Layout then
ViewPager.OnPageChangeListener's onPageScrolled method
try one of this to add margin between fragment
setPageMargin(int marginPixels)
setPageMarginDrawable(Drawable)
setPageMarginDrawable(int)
after that you can show hide your image with your logic.

Related

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

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.

ViewPager - Same background image spread out over three views

If I wanna use, say a picture, on a viewPager but spread each third of the picture onto the three different views of the viewPager, is this possible to do? If so, how?

Overlap a layout with viewPager

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

Categories

Resources