应该在哪里使用PageViewer? [英] Where should use PageViewer?

查看:105
本文介绍了应该在哪里使用PageViewer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已实施 ViewPager 和数量的片段作为孩子,这里的每一个孩子改写自己的 onAttach,onCreateView,onViewCreated和setUserVisibleHint

I have implemented ViewPager and number of Fragment as child, here every child override own onAttach, onCreateView, onViewCreated and setUserVisibleHint.

在我的应用程序导航的行为是随机的,它并不是每次都按顺序排列。由于网页浏览器的执行缓存以加载额外的孩子,这是我的问题是。我不知道什么时候我应该初始化/释放子类的成员。

In my app navigation behaviour is random, it not be in sequence every time. Since page viewer perform caching to load extra child, and this is what my problem is. I am not sure exactly when I should initialise/release member of child class.

这是你们需要的建议,会是preferable使用PageViwer在这种情况下,还是应该包括每个组成部分的传统活动流走了。

Required suggestion from you guys, will it be preferable to use PageViwer in this case or I should go with traditional activity flow for each of component.

推荐答案

ViewPager 通常用于移动效率水平的项目,以项目的导航。典型的用例是

ViewPager is typically used for move efficient horizontal item to item navigation. Typical use cases would be

  • 通过对相关物品刷卡(例如电子邮件,图片,歌曲专辑等。)
  • 标签之间的刷卡
  • 刷卡回来,来回的精灵般的活动

有关详细信息,你可以阅读有关刷卡视图Android的设计模式

For more details you can read a section about Swipe Views Android Design pattern.

关于生命周期,它基本上采用了相同的生命周期的任何其它片段。唯一不同的是,该生命周期方法可以被调用,因为碎片的缓存 ViewPager 工具有点晚或早于您预期。

Regarding the lifecycle, it basically uses the same lifecycle as any other Fragment. The only difference is, that lifecycle methods can be called a bit later or earlier than you expect, because of fragment's caching ViewPager implements.

我不知道什么时候我应该初始化/释放子类的成员。

I am not sure exactly when I should initialise/release member of child class.

您应该主要靠两种方式: ONSTART()的onStop()。在 ONSTART()创建类成员和初始化你想要的一切。在的onStop()方法,你应该取消初始化一切,并删除在 ONSTART将所有监听器()

You should basically rely on two methods: onStart() and onStop(). In onStart() you create class members and initialize everything you want to. In onStop() method you should deinitialize everything and remove all listeners you set in onStart().

方法 setUserVisibleHint()独立 ONSTART()的使用的onStop() 。您 768,16最好不要初始化或有破坏任何东西。你千万不要认为这是对一个生命周期的方法,因为它不是。它的存在只是为了给你一个提示,你的片段是对用户可见。在这里,您可以启动或停止动画,或请求数据更新或执行类似的任务。这是该方法的唯一目的。

Method setUserVisibleHint() is used independently of onStart() or onStop(). You shoud better not initialize or destroy anything in there. You must not consider it to the a lifecycle method, because it's not. It's there just to give you a hint, that your fragment is visible to the user. Here you can start or stop animation, or request data update or perform similar tasks. This is the only purpose of this method.

要求的建议,会是preferable使用   PageViwer在这种情况下,还是应该用传统活动顺其自然   对于每个组件的

Required suggestion from you guys, will it be preferable to use PageViwer in this case or I should go with traditional activity flow for each of component.

如果你的活动融入提到的要点之一,我会建议你使用 ViewPager 。否则,你可能会考虑其他的选择。

If your activity fits into one of the points mentioned about, I would suggest you to use ViewPager. Otherwise you might consider other options.

更新:您很有可能将不会覆盖的onCreate()的onDestroy()片段的生命周期方法非常频繁。您可以使用 onCreateView() onDestroyView()方法来代替。这里可以实现所谓的静态初始化,这并没有改变,而一个片段是还活着的初始化。这是布局的初始化和类似的任务。

Update: Most likely you won't override onCreate() and onDestroy() lifecycle methods of a fragment very often. You will use onCreateView() and onDestroyView() methods instead. There you can implement so called static initialization, the initialization which doesn't change while a fragment is still alive. This is layout initialization and similar tasks.

这篇关于应该在哪里使用PageViewer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆