Android的:如何使无限滚动型无尽的滚动Android

2023-09-06 15:04:45 作者:纯如小白花的少年^

我想code键使滚动视图上显示相同的图像无尽的滚动和喜欢上它周围滚动的自我?

i want code to make the scroll-view show the same images with endless scrolling over and over like scroll around it self ?

这是当然的布局,想知道什么是code,使之无限滚动视图无尽的滚动。

this is ex for the layout and want to know what is the code to make it infinite scroll-view with endless 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>

推荐答案

使用一个ListView和被稍微修改具有无限元素的适配器

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());
}

从本质上讲,你告诉它的计数是MAX_INT欺骗它,然后当你去得到一个项目使用mod得到的顺序正确的项目。

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.

在这里看到: Android的无尽列表

和CommonsWare有支持此行为,以及一个组件: https://github.com/commonsguy/ CWAC-无尽

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