Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:how to make infinite scrollview with endless scrolling

I want a code to make the ScrollView show the same images with endless scrolling over and over.

This is excelent for the layout and I want to know what is the code necessary for adding it to a ScrollView with infinite scrolling.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<HorizontalScrollView
    android:id="@+id/horizontalScrollView1"
    android:layout_width="match_parent"

    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
           <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />
           <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" />


    </LinearLayout>
</HorizontalScrollView>

like image 732
user2895395 Avatar asked Oct 19 '13 17:10

user2895395


People also ask

How do I turn endless scroll on?

Disabling Infinite Scroll However, you can turn it on or off any time by toggling the “Infinite Scroll” option on My Site → Settings → Writing.

How do I add infinite scroll?

Method 1: Adding Infinite Scroll with Catch Infinite ScrollYou need to click on it to configure the plugin settings. To start with, you need to choose a trigger option for loading articles. You should select the 'Scroll' option to trigger autoload with scrolling.

What is infinite scroll Android?

A common application feature is to load automatically more items as the user scrolls through the items (aka infinite scroll). This is done by triggering a request for more data once the user crosses a threshold of remaining items before they've hit the end.

Is infinite scroll better than pagination?

Pagination works best on websites where users are looking for specific pieces of content. Infinite scroll is better suited for the exploration of content, where users are browsing aimlessly for something interesting.


1 Answers

Use a ListView and an Adapter that is modified slightly to have "infinite" elements

Here are the changes to your the Adapter that would support this behavior:

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

@Override
public ImageItem getItem(int position) 
{
    return mItems.get(position % mItems.size());
}

Essentially you trick it by telling it that the count is MAX_INT and then when you go to get an item use mod to get correct item in the sequence.

Several people have proposed different solutions to this already as well.

See Here: Android Endless List

and CommonsWare has a component that supports this behavior as well: https://github.com/commonsguy/cwac-endless

like image 99
FoamyGuy Avatar answered Oct 29 '22 10:10

FoamyGuy