开发者

Issue with Gallery

I am extending Gallery class & displaying scrollable images in a horizontal manner. I am displaying only on the landscape mode.

For displaying the images , I am using BaseAdapter , since I need to place text & icon over the images.

I am displaying the no of images based on a condition which is set.

I want to put the following conditions.

i> If the no of image to be displayed is 1 , I'll only show a single image on the middle of the screen & there should not be any scrolling.

ii> If the no of images to be displayed is 2 , then both the images should be shown sid开发者_如何学编程e by side(horizontal) & without any scrolling.

iii> Only if the no of images is equal to or greater than 3 , then images should be displayed in the horizontal manner & scrollable.

How can I handle all the above cases using a single layout xml & by handling the conditions source code.

Kindly provide me your inputs/sample code.

Thanks in advance.

Warm Regards,

CB


well for showing the text and the image you will need to create a custom adapter override the getView method and a custom layout (a linear layout with vertical orientation containing a textView and an ImageView) inside the getView. You can find a lot of examples of doing that on google, its pretty simple.(there is the gallery example on the android developers page that explains this). Hello Gallery

For your conditions you can probably make something like this in the adapter constructor or the actual creation of the adapter in the activity. i think by default it wont be scrollable for 1 item, but for 2 it will be since the gallery centers the selected item... which is pretty lame. and for 3 or more it will work as intended (show a scrollable horizontal list of items).

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜