简体   繁体   中英

Infinitely scroll image inside a scroll view in android

So basically i have a an imageview inside a scrollview, what i want to do is be to be able to scroll infinitely without ever reaching the bottom of the scrollview. Can this be done in any way ? the image of course will have to be repeated .. but any other method is appreciated

You can use a ListView and an Adapter that is modified slightly to have "infinite" scroll.The change required in your Adapter is something like this:

@Override
public int getCount()
{
    return Integer.MAX_VALUE;
}

The trick here is to tell it that the count is MAX_INT .However by doing this, it will make scroll downwards infinitely but not backwards.

In order to make the list go backwards, as in an infinite carrousel, you can trick the system by setting the default element to be something like Integer.MAX_VALUE/2 by calling:

listView.setSelection( Integer.MAX_VALUE/2 );

By doing this, it makes the effect of infinite carrousel in both directions.I think presence of ImageView will not be a problem and it should work then too.Hope this helps.

Edit

For this, as you need to learn how to make a custom ListView and a Adatper , i suggest you to follow this easy and short tutorial .You can also download the entire project from that link.After running that project, add the above mentioned code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM