Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The main idea is that in your <code>getView</code> method, you have to use </p> <pre><code>position = position % imagesArray.length; if (position &lt; 0) position = position + imagesArray.length; </code></pre> <p><strong>imagesArray</strong> is the array that holds the images in your res folder. For example:</p> <pre><code>public class CircularGallery extends Activity { /** Called when the activity is first created. */ private Integer[] imagesArray = { R.drawable.picture1, R.drawable.picture2, R.drawable.picture3, R.drawable.picture4, R.drawable.picture5, R.drawable.picture6 , R.drawable.picture7 }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Gallery g = (Gallery) findViewById(R.id.gallery); g.setAdapter(new ImageAdapter(this)); g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { if (position &gt;= imagesArray.length) { position = position % imagesArray.length; } Toast.makeText(CircularGallery.this, "" + position, Toast.LENGTH_SHORT).show(); } }); } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private Context mContext; public ImageAdapter(Context c) { mContext = c; TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return Integer.MAX_VALUE; } public Object getItem(int position) { if (position &gt;= imagesArraylength) { position = position % mImageIds.length; } return position; } public long getItemId(int position) { if (position &gt;= imagesArray.length) { position = position % imagesArray.length; } return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView i = new ImageView(mContext); if (position &gt;= imagesArray.length) { position = position % imagesArray.length; } i.setImageResource(imagesArray[position]); i.setLayoutParams(new Gallery.LayoutParams(80, 80)); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setBackgroundResource(mGalleryItemBackground); return i; } public int checkPosition(int position) { if (position &gt;= imagesArray.length) { position = position % imagesArray.length; } return position; } }} </code></pre> <p>Also, some developers have done such a functionality and you can find sources on their blogs</p> <ul> <li><p><a href="http://abhinavasblog.blogspot.com/2011/09/android-infinite-looping-gallery.html" rel="nofollow noreferrer">http://abhinavasblog.blogspot.com/2011/09/android-infinite-looping-gallery.html</a></p></li> <li><p><a href="http://blog.blundellapps.com/infinite-scrolling-gallery/" rel="nofollow noreferrer">http://blog.blundellapps.com/infinite-scrolling-gallery/</a></p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload