开发者

How to have a gallery with a changeable icon overlayed upon each image in Android?

  • I've got an array of images, which I want to display in a gallery.
  • I want each image to have a small icon overlayed inside it, on the bottom right hand corner (e.g. a light bulb).
  • When the user clicks on the image or the icon, the icon will change from the 'lighbulb_off' image to the 'lightbulb_on' image, and t开发者_JS百科he index of the clicked image will be added to a Vector of 'clicked images'.

Is there a way to have a custom layout for each item in a gallery? If so, each gallery item could be the original image, with the icon positioned within it using a RelativeLayout.


Is there a way to have a custom layout for each item in a Gallery?

Yes. You need to extend ArrayAdapter and override getView() to do what you want. Here is a free excerpt from one of my books that discusses the concept -- while it uses ListView as the example, the same technique should apply for Gallery.

Note that this excerpt should be updated in the next ~12 hours to be much improved, so, um, don't rush to download it right away. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜