Android “不推荐使用画廊类型”,最好的选择是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11868503/
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
"The type Gallery is deprecated", Whats the best alternative?
提问by Omar
I was really surprised that such a Widget gets deprecated.
I want a simple gallery that scrolls left and right, shows a picture on the whole Activity screen, and most important is that you cant swipe more than 1 image in any direction, even if the scroll speed is fast it changes to the next image.
我真的很惊讶这样的 Widget 被弃用了。
我想要一个左右滚动的简单图库,在整个 Activity 屏幕上显示一张图片,最重要的是你不能向任何方向滑动超过 1 张图片,即使滚动速度很快它也会切换到下一张图片。
So which Widget should I use? Or should I use a simple ImageView and handle all the swipes and add an animation?
那么我应该使用哪个 Widget?或者我应该使用一个简单的 ImageView 并处理所有滑动并添加动画?
回答by FoamyGuy
It states in the docs:
它在文档中指出:
This widget is no longer supported. Other horizontally scrolling widgets include HorizontalScrollView and ViewPager from the support library.
不再支持此小部件。其他水平滚动小部件包括支持库中的 HorizontalScrollView 和 ViewPager。
HorizontalScrollView will be closer to what you are looking for I think.
我认为 HorizontalScrollView 将更接近您正在寻找的内容。
I suspect that Gallery was deprecated because it did not properly use convertView with its adapter. Which meant that it had to create a new view for every item which was a drain on performance.
我怀疑 Gallery 已被弃用,因为它没有正确使用 convertView 及其适配器。这意味着它必须为每个项目创建一个新视图,这会消耗性能。
Another option you have is to use the 3rd party created EcoGallerywhich Joseph Earl created to overcome the issue, this version does recycle its views properly. Unfortunately that pastebin linkis the only reference to it I can find online now.
您的另一个选择是使用由约瑟夫·厄尔 (Joseph Earl) 创建的第 3 方创建的 EcoGallery来解决该问题,此版本确实正确回收了其视图。不幸的是,pastebin 链接是我现在可以在网上找到的唯一参考。