Here is a sample from duolingo app:
I want to implement a similar feature. I can use ViewPager to make swiping tabs. What I can't seem to figure out is how to display the adjacent tabs (part of it) alongside the current tab, which is in the center.
I initially thought of implementing this using horizontal LinearLayout, but I don't know how to make the snapping effect. And it also seemed more reasonable to use something which already provides you with swiping and snapping than try to implement your own.
Using ViewPager also let's me use fragments and memory management is also effective for cases of more than a few tabs.
Any help will be appreciated. Thank You in advance.
Related
What I would like to achieve: Have a ViewPager with TabLayout where each Tab contains a new Fragment that has a RecyclerView layout out horizontally and managed by a FragmentPagerAdapter.
What I am struggling with: The default behaviour is that when you get end of the list on one of the tabs, it switches Tabs and snaps (snapping means if you pull over 50% of the viewport, it jumps to either direction). I want it to free-flow and not to snap. Sort of like how it happens in iOS by default.
I got inspired for this setup by the following two CodePath guide:
https://guides.codepath.com/android/google-play-style-tabs-using-tablayout
https://guides.codepath.com/android/ViewPager-with-FragmentPagerAdapter
How should I approach this problem (preferably without any other libraries)?
What I would do is use HorizontalScrollView instead of a ViewPager. The only caveat is that the view pager sends the lifecycle events to fragments as you scroll between them, whereas for HorizontalScrollView you will have to add them initially, and then they will be continuously active unless you manually change that. Also you may have an option to not use the fragments and use simple views depending on what you use the fragments for.
I would definitely not override the touch events for the ViewPager because it does some cleanup when it detects the UP motion, so just swallowing it is not a correct thing to do.
I would like to achieve a navigation in my app like Pinterest or Trello, that is, kind of three tabs to navigation + horizontal scrolling.
I have made a custom tabbar for this (since I couldn't guess how to change tabs width in my actionbar with navigation TAB mode). So I have three buttons to navigate from one fragment to another. Now I would like to implement the horizontal scrolling like these two examples, to also navigate among my fragments.
I have read about View Pager but I don't know if it fits to my case, since I don't have only views but fragments. Does anybody have an example or an idea of how to do it? Could I apply it among different activities?
Thanks
Please take a look at the duplicate question that I just answered:
How to implement a swipe-gesture between Fragments?
I suppose the Android ViewPager is what you are looking for:
http://developer.android.com/reference/android/support/v4/view/ViewPager.html
Here is a nice tutorial on how to implement it:
http://developer.android.com/training/animation/screen-slide.html
The basic idea is that you have multiple Fragments, each representing
a different Screen. The ViewPager enables the user to swipe between
the different Fragments and display different content.
You can use ViewPager. More information about viewpager this.
I am concern about the ViewPager or ViewFlipper. I don't want to use ViewPage. So I want to know how to swipe between Layout or activity. Can anyone suggest me with source code. Thanks in advance.
I cannot understand why you don't want to use ViewPager. You'll be able to swipe between everything you want(activity, layout). It's not difficult to use it and to customize it. There is a plenty of examples:
Fragments
General
you can easily surf through the i-net to look for more examples
I am getting stuck in one stage. I have a total of 20 to 25 images that should get animated like ViewPager does. Now on all the images I have onClick() events and I don't know if I should work with ViewPager or ViewFlipper. I can implement both things, no issues here.
What I Want : I just want a suggestion that according to my problem which will be the best option, ViewFlipper or ViewPager?
What I Have Searched : I have gone through different links on StackOverflow, namely How to improve the performance of ViewFlipper/ViewAnimator and ViewFlipper vs Fragments, but I could not find the thing I want.
I have worked with ViewPager somewhat, but at that time there were just 3 or 4 Fragments I had to manage. If I were to use it to solve this problem I have to manage 25 Fragments this time. So I am wondering if there is a better solution available.
I have also done a little R & D on ViewFliper and know that it has only one Activity I have to manage but it does not have the animation accuracy that ViewPager has.
Please suggest me whether I should go for ViewPager or ViewFlipper?
Thanks in Advance.
Update (from 5+ years old original post):
Use ViewPager2 from JetPack. That's it.
I left original answer below but just for reference. Please do not use very old and not maintained widgets (like Gallery and ViewFlipper any more):
Intro: On first thought, I would recommend Gallery widget instead of ViewFlipper but it is depreciated since JellyBean (API 16), probably because of bad recycling of non-visible elements implementation.
Answer: What u really should use now is ViewPager or HorizontalScrollView. In your case (despite not too much given details) I think is better ViewPager because according to documentation:
.. HorizontalScrollView is a FrameLayout, meaning you should place one
child in it, containing the entire contents to scroll ..
On the other side for ViewPager you should implement PagerAdapter to generate pages which will be shown in this view.
My final answer is A, ViewPager ;)
Hope u will find this helpful ;) Cheers
Android News & Weather app lets you swipe to reveal another view, just like the iPhone. Can someone show me an example of how this is done?
It is not a ViewFlipper attached to a GestureDetector.
It is a custom view, you can see how it's done in Launcher by looking at Workspace.java in packages/apps/Launcher2 at android.git.kernel.org.
You can now do this out-of-the-box in the Android Compatibility library with a ViewPager: http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html?m=1
ViewPager slides between Fragments much the same way ListViews scroll up and down with views.
If you're not interested in scrolling the tabs, there's an example in the SDK that uses a TabHost (instead of making the tabs themselves scrollable left-to-right), but you need not use a TabHost. You could, if you wanted horizontally-scrolling tabs, use a HorizontalScrollView with some buttons in it.
For an approach that doesn't use the compatibility lib, or fragments, see here: https://github.com/olibye/AndroViews