2010-06-25 52 views
3

我有图片构件包含1-10张图片可以滑动。我知道当我对屏幕进行条纹扫描时,图像会从左向右滚动。我想自动循环图库10自动启动后的第一个图像,有没有自动圆形适配器或方式?Android自动循环图库

  final Gallery g = (Gallery) findViewById(R.id.gallery); 
     g.setAdapter(new ImageAdapter(this)); 
     Animation animation = AnimationUtils.loadAnimation(this, 
     R.anim.rotate_indefinitely); 

     animation.getInterpolator(); 
     animation.setDuration(1000); 
     animation.setStartOffset(200); 
     animation.setRepeatMode(2); 
     animation.setFillAfter(false); 
     animation.setFillEnabled(true); 

     g.setAnimation(animation); 
     g.startAnimation(animation); 

,但我只看到第一幅图像动画..

看看我的Video ...

回答

8

写出在它返回Integer.MAX_VALUE的画廊SpinnerAdapter是getCount将( ) 方法。然后,当在getDropDownView()和getView()中返回一个View时,将实际项目计数的模数应用于position参数。

+0

你想要一个无尽的画廊,从滚动到最后的第一项开始,对吧?因此,您认为它包含的物品多于当前物品,并在Adapter的getView()中添加位置%= itemsCount,以使其在最后一个物品之后排列第一个物品。 – ognian 2010-06-25 11:06:01

1

我实现了一个最简单的解决方案。 只需returns Integer.MAX_VALUE in it's getCount() method 这将使无限池在右侧。 使其成为双面 pass Integer.MAX_VALUE/2 in the position of child in setSelection(position, animate) 很酷。

+0

非常感谢Pervez Alam。你拯救了我的一天。 – 2015-09-06 12:10:47

+0

欢迎您:) – 2015-09-14 06:56:03