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

1

27

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.

Sericin answered 23/10, 2012 at 13:29 Comment(0)
F
33

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

Front answered 7/11, 2012 at 7:38 Comment(3)
And why that is?Leucoplast
@Front Can you elaborate on the answer? I don't understand much how you arrived at the conclusion of going for ViewPager instead of ViewFlipper :(Idolize
ViewPager2 is better if you have huge number of items. ViewPager2 is based on RecyclerView, it will recycle it's child instead of rendering it all at once.Aver

© 2022 - 2024 — McMap. All rights reserved.