开发者

how to create vertical cyclic image views in android...?

I want a view, where 5 images scroll vertically and repeatedly (loop). How to achieve this in android..?

I tried Gallery view but it will not support vertical view.

I tried transition animation, it sh开发者_如何学Cows vertical but not in a loop.

I tried dynamically adding views in a layout but its not appropriate.

How to achieve this, please help..? Thanks in advance..


This is a demo created for one of my projects. It give you some idea.

Here I scroll through the images in a loop.


You can do this using a very simply ListView. In the ListView's Adapter.getView() method simply modulo the position by the total number of items in the list:

public View getView(int position, View convertView, ViewGroup parent)
{
     position = position % nObjects; // nObjects if the total number of objects to display
     // Code to get the new view is below this
}

One advantage of doing it this way is the OS will take care of recycling old views and clearing up memory. Where as if you create and destroy the views yourself you will have to do that manually.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜