ViewFlipper 和 ViewSwitch 的区别是什么

他们都继承了 ViewAnimator。我知道 ViewSwitcher只允许两个视图,而 ViewFlipper允许更多。但是为什么 Android 创建了 ViewSwitcher,如果它只是一个有两个视图的 ViewFlipper?还有别的区别吗?在什么条件下使用一个优于另一个?

32646 次浏览

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.

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.

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

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

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