前段时间就发现Gallery这个控件被无情的打上了过期这个烙印。当时很好奇,谷歌为什么就让它过期了,不过那个时候项目忙就没有仔细去看了,反正过期了还能用,只是不维护了嘛。今天刚好有点时间就翻了翻android SDK文档:
This class was deprecated in API level 16.
This widget is no longer supported. Other horizontally scrolling widgets include HorizontalScrollView and ViewPager from the support library.
啊哦,在API level 16(Android 4.1)就过期了,也就是谷歌不在维护这个类了。谷歌还推荐了可以用HorizontalScrollView 或者ViewPager 来代替它。
首先,先给Gallery默哀一分钟吧,过期了,离死也就不远了。这期,我们先谈谈Gallery为什么会被谷歌判了死刑吧。
网上查了一圈,最后只在stackoverflow找到了一个类似的问题和一个疑似答案的答案,附上问题链接:
这个控件过期了,HorizontalScrollView 或者ViewPager该换用哪个?
我怀疑Gallery过期的原因是因为它的适配器不能合适的转换视图,它每次切换图片时都要新建视图造成浪费太多的资源。
另外你可以选择使用The third part created ecogallery,它克服了gallery不能回收视图的缺点;但不幸的是,通过网络只在pastebin上找到它的有关资料。(这句话无视吧,那个链接访问不了)
Replacement for Gallery widget in Android with View recycling. This originally made by Joseph Earl (details).
Usage:
1- Include 'EcoGallery' android library to your project. (Eclipse project: properties -> Android -> Library - Add)
2- You could declare EcoGallery in the layout xml file, Example:
<us.feras.ecogallery.EcoGallery
android:id="@+id/images"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
/>
3- Use EcoGalleryAdapterView instead of AdapterView.
For a complete tutorial check the wiki.
Sample App
Click here to view the sample app
Change Log:
June 24, 2013
Compiler warnings fixed @mnowrot
Limitation:
The existing implementation assumed that each different position in the adapter resulted in a unique view. The changes are only good if your Gallery contains only one type of item, if not you'll need to add some sort of key based on item type and the amount of that type required.
374



被折叠的 条评论
为什么被折叠?



