How to use PagerTitleStrip in ViewPager2? - android

I have a standard implementation of PagerTitleStrip in ViewPager but it cannot work in ViewPager2. If I want to migrate to ViewPager2, how should I implement PagerTitleStrip within ViewPager2? I found solution and many detailed info regarding how to implement PagerTabStrip behaviour using TabLayout but it is not applicable to PagerTitleStrip.

ViewPager2 based on RecyclerView and implement only a limited subset of old ViewPager features.
Currently you cannot properly use neither PagerTitleStrip nor PagerTabStrip with ViewPager2.
Frankly I don't even know usecase where TabLayout with custom themed tabs and indicator and, maybe, some little extra code won't suffice.
Thus the only solution for ViewPager2 as for now is to use TabLayout.
Maybe if you will ask a question in context of your usecase or needed design - there will be a more detailed answer.
Hope it helps.

Currently ViewPager2 has many bugs, that should be fix may be in future.
while i was working on same i also found a bug and because of that i am unable to use ViewPager2 properly.
For now it should be good if you use ViewPager only and avoid to use ViewPager2 for some time.
Or the suggestion of Paul Ost is also good and acceptable.

Related

Nested tabs with viewpager swiping in android?

I've implemented nested tabs with view pager with no problems, but my problem is on the swiping part,
When I do the swiping action the main activity tabs will be switched, but I want the fragment to swipe instead. how can I achieve this?
I've tried implement main tab with tab host and fragment tabhost which doesn't have swiping feature at all, but that disabled whole swipe on the main and fragment together.
Instead of custom library you can try to use Bottom navigation view for bottom bar which has been added to version 25 of the Design Support Library. Here is an Article about it.
So android.support.design.widget.BottomNavigationViewin your activity together with android.support.design.widget.TabLayout and ViewPagerin fragment should work the way you want it to work. And this will also provide good UX (similar to one implemented in Google Plus App)
hello shaheen zahedi maybe it's possible please..with..below
just set bottom tab changed listener
like..
btnTab.setTabChangeListener(null);
You can disable view pager swiping on a particular ViewPager.
But I would suggest to not make 2 ViewPagers on the same screen.
Your bottom TabLayout and corresponding ViewPager can be replaced with BottomBar library.
I feel like it is wise to follow the Google Material guidelines. Not sure if you checked it out already...
Either way, here is what Google considers best practice for lateral navigation between tabs. Hope it helps!
I made a sample project with nested tab and fragment. may be it might help what is you looking for.
following link to download:
NestedTabWithFragment

How to display adjacent tabs in ViewPager?

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.

How to create a Hulu or IMDB style ViewPager in Android?

I've only been learning android for a few days now (beginner) and I'm quite not able to create a ViewPager as fine as these:
Is it possible to create a ViewPager inside a Fragment. If so any clue on how to proceed with creating such?
As a side note can some also please answer this question: I read somewhere that nested Fragments are possible, is that how these apps are created?
could you put a ViewPager in a fragmnet? Yes, Is this what they are doing? I dont know.
Quick example of setting up nested fragments is here
It could be an activity with a viewpager at the top in a scrollview too
You can do this. You have to use ViewFlipper and have multiple layouts within that PageViewer, each will be a "page." Here is a good tutorial on how to use this.
http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/

How to swipe between pages or layouts without using ViewPager or ViewFlipper?

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

Android : ViewFlipper Or ViewPager - Which is the better option?

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

Categories

Resources