翻转许多(超过 40 张)图像的好方法是什么?
我研究过 ViewFlipper,但在一个 XML 文档中定义 40 个不同的视图似乎不是一个好主意。我知道一定有更好的方法,但我不知道该怎么做。我花了一些时间试图找到答案,到目前为止还没有好的答案。
Ive looked into the ViewFlipper, but defining 40 different views in one XML doc just doesn't seem like a bright idea. I know there has to be a better way, I just don't know how. I have spent some time trying to find a answer with no good answer so far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经使用 Gallery 小部件(诚然经过大量修改)在图像查看器中为客户显示 200 张全屏图像。
或者,您可以使用具有 2 个(在本例中为 ViewFlipper)或 3 个视图(如果您想预加载下一张和上一张图像,则为 3 个)的 ViewAimator。如果您采用这种方法,那么劳伦斯(Laurence)比我提出了这个想法;)但是我要补充一点,您希望扩展 ViewAnimator/ViewFlipper 类以允许它接受某种类型的适配器。
I have used the Gallery widget (admittedly quite heavily modified) to display 200 fullscreen images in an image viewer for a client.
Alternatively you could use a ViewAimator with either 2 (in this case ViewFlipper) or 3 views (3 if you want to preload both the next and previous images). If you go for this approach then Laurence beat me to suggesting this idea ;) However I'd add that you would want to extend the ViewAnimator/ViewFlipper class to allow it to accept some type of Adapter.
一种简单的方法是在 ViewFlipper 中简单地包含两个 ImageView。然后,当您请求下一个或上一个视图时,为下一个视图设置新的图像资源并翻转。
如果您使用 AsyncTask 或 Handler 这将阻止你的 UI 线程阻塞。
希望这有帮助!
A simple approach would be to simply contain two ImageViews within the ViewFlipper. Then when you request the next or previous view, set the new image resource for the next view and flip.
If you implement a lazy loader using AsyncTask or a Handler this will stop your UI thread from blocking.
Hope this helps!
您可以使用 ViewPager (包括在 Android 兼容性库中,如果您需要支持预蜂窝设备)。
You could use a ViewPager (included in the Android compatibility library if you need to support pre-Honeycomb devices).