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

Bhavesh Patadiya picture Bhavesh Patadiya · Oct 23, 2012 · Viewed 23.6k times · Source

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.

Answer

Ewoks picture Ewoks · Nov 7, 2012

intro: On first thought I would recommend Gallery widget instead of ViewFlipper but it is depreciated (0.o) since JellyBean (API 16), probably because of bad recycling of nonvisible 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