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.
Related
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.
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
I have a tabbed ViewPager which lets the user jump to the corresponding page depending on which tab they press. The problem is that you see the view pager scroll really quickly to the selected page, meaning you get small glimpses of each its scrolls through. Is there a way to stop this and jump instantly without seeing other pages.
Call setCurrentItem(itemPosition, false) on your ViewPager instance. As per the documentation the second parameter is smoothScroll effect which causes the glimpses of the other fragments.
I have used the Android Design Support library and implemented tabs in my android app using tablayout, fragments and viewpager. Tab sliding is working perfectly. But when I add more tabs (say 7), those tabs reduce their width and adjust themselves. How to show only 3 tabs at a time and show the next three when the user slides from 3rd to 4th tab?
In your MainActivity
ViewPager mpager;
TabPageAdapter adapter = new TabPageAdapter(getSupportFragmentManager(), list);
mtabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
mpager.setOffscreenPageLimit(list.size());
mpager.setAdapter(adapter);
In your xml TabLayout set
app:tabMode="scrollable"
you can use sliding tablayout
http://www.tutorialsbuzz.com/2015/04/Android-Material-Design-Sliding-TabLayout.html
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