What's the difference between ViewFlipper and ViewSwitcher

前端 未结 4 1163
傲寒
傲寒 2021-01-29 23:49

They both inherit ViewAnimator. I know that ViewSwitcher allows only two views, while ViewFlipper allows more. But why did Android create

4条回答
  •  借酒劲吻你
    2021-01-30 00:22

    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.

提交回复
热议问题