91

They both inherit ViewAnimator. I know that ViewSwitcher allows only two views, while ViewFlipper allows more. But why did Android create ViewSwitcher, if it is just a ViewFlipper with 2 views? Are there any other differences? On what condition will be using the one superior than the other?

Dimitar
  • 4,402
  • 4
  • 31
  • 47
user412759
  • 2,375
  • 3
  • 22
  • 20

4 Answers4

86

From what I can tell, ViewSwitcher is used if you want to switch between two views like you said. Useful if you have 2 views that you have to go back and forth fairly regularly. And the class implements a ViewFactory if you wish to use it.

However, ViewFlipper can be used if you want to periodically change the views. Say like an automated flipping book of some sort. Though a custom-adapter gallery is much better at this.

And yep, that's all. They really aren't that much more useful than the ViewAnimator. Why Android development makes anything is really a mystery to me.

I would normally just prefer using a ViewAnimator because it gives you more freedom and thus flexibility in how you design. But if you want features like the ViewFactory and you only got 2 views use the ViewSwitcher. If you want to be able to periodically change views use ViewFlipper. If you don't need either use a ViewAnimator.

Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57
alexanderjslin
  • 1,139
  • 8
  • 6
  • Having implemented a view flipper that contains approximately 10 custom views of mostly text, and waiting for 5 seconds for the first load, I'm thinking the benefit of a view factory is to make initialization quicker. I'm also getting slow response on forward and back buttons. There's something wrong with the ViewAnimator, not sure why it should take so long. I'll be profiling it with traceview later this week and will post back with what I learn. – William T. Mallard Nov 24 '13 at 21:03
  • 1
    @WilliamT.Mallard It's 2020. – Mitch Jun 24 '20 at 01:39
15

ViewFlipper supports more than two views, ViewSwitcher only supports 2.

Evan R.
  • 1,210
  • 1
  • 27
  • 42
7

I'm not sure if there's any big differences between them but from what I've gathered the difference is that ViewSwitcher is used in circumstances where the view is the same but the data is different - like on a calendar app - we're just changing the data in the view.

digitalWestie
  • 2,647
  • 6
  • 28
  • 45
0

ViewFlipper is allowed in app widgets, while ViewSwitcher is not.

https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

TalkLittle
  • 8,866
  • 6
  • 54
  • 51