Android ViewFlipper 和 ViewSwitcher 有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3542312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:41:16  来源:igfitidea点击:

What's the difference between ViewFlipper and ViewSwitcher

android

提问by user412759

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

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

采纳答案by alexanderjslin

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.

据我所知,如果您想像您说的那样在两个视图之间切换,则使用 ViewSwitcher 。如果您有 2 个视图必须定期来回切换,则很有用。如果您想使用它,该类将实现一个 ViewFactory。

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.

但是,如果您想定期更改视图,则可以使用 ViewFlipper。像某种自动翻书一样说。尽管自定义适配器库在这方面要好得多。

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.

是的,仅此而已。它们实际上并不比 ViewAnimator 有用得多。为什么 Android 开发能做出任何事情对我来说真的是个谜。

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.

我通常更喜欢使用 ViewAnimator,因为它为您提供了更多的自由度,从而在您的设计方式上具有更大的灵活性。但是,如果您想要 ViewFactory 之类的功能,而您只有 2 个视图,请使用 ViewSwitcher。如果您希望能够定期更改视图,请使用 ViewFlipper。如果您不需要,请使用 ViewAnimator。

回答by Evan R.

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

ViewFlipper 支持两个以上的视图,ViewSwitcher 只支持 2 个。

回答by digitalWestie

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.

我不确定它们之间是否有任何大的差异,但从我收集的信息来看,不同之处在于 ViewSwitcher 用于视图相同但数据不同的情况 - 例如在日历应用程序上 - 我们只是更改视图中的数据。

回答by TalkLittle

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

应用小部件中允许使用 ViewFlipper,而不允许使用 ViewSwitcher。

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

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