Make ViewPager swipable through external layout / from outside - java

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

Related

Viewpager2 Scrolling issue? This is not about Nested scrolling

Please note this is not about nested scrolling.
Recently i switched to ViewPager2. I have setup viewpager2 with a tabview (viewpager2 is horizontal). So on one of the fragment has a recyclerview. So when I scroll down on the recyclerview, some times the viepager2 switches tabs. This was not happening on the old viewpager. So if I need to scroll the recyclerview without changing the viewpager2 tabs, I need to carefully touch and drag 100% vertically like a straight line. if the touch is not a straight line, the viewpager2 switches tabs. If anyone can point me towards a fix, I would be glad. Thanks
I did try the NestedScrollableHost wrapper and it did not help.

android - instantly swap page on swipe gesture in ViewPager

I have a TabLayout with a ViewPager connected. I want to forbid user to drag it slowly, I mean I want ViewPager change its pages on swipe gesture with the same instant behaviour as clicking on Tabs do.
I tried to remove swipe in ViewPager, but since it's content can be really big I can't leave it as it is.

android - slide relativelayout to the side with static buttons

In my Activity I have two RelativeLayouts and two buttons. When you first open the Activity, you have to see a RelativeLayout and the buttons. Then you can slide the RelativeLayout to the right or to the left. The buttons don't move. While sliding, you see the other RelativeLayout below. After a completed slide you see the full RelativeLayout that was below.
How can I implement this in my Android application (min SDK version 14)?
Code examples are a big plus, but not necessary. It is ok to show me the way :)
There's something called a navigation drawer which comes as a template in Android Studio. There are also many sliding menu libraries out there: https://android-arsenal.com/search?q=sliding specifically you might look at https://android-arsenal.com/details/1/1429
If you want to do it from scratch, it'll go something like: have one layout, say a Frame Layout as your root. Then you add the two Relative Layouts and your buttons. Then you need to implement a OnTouchListener in your activity and set on the relative layout that can slide: when the MotionEvent is ACTION_MOVE, you need to calculate the difference between the last touch event and the current touch event and then you can call translateX(dx) on the sliding relative layout where dx is the calculated difference.

Image between fragments in a viewpager while swapping

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.

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