Code example for Gallery

Methods: getCount, getSelectedItemPosition, setSelection

0
					upX=(int) event.getX();//取得松开时的坐标
					int index=0;
					if(upX-downX>100)//从左拖到右,即看前一张
					{ 
						//如果是第一,则去到尾部 
						if(gallery.getSelectedItemPosition()==0)
						   index=gallery.getCount()-1;
						else 
							index=gallery.getSelectedItemPosition()-1;
					} 
					else if(downX-upX>100)//从右拖到左,即看后一张
					{ 
						//如果是最后,则去到第一 
						if(gallery.getSelectedItemPosition()==(gallery.getCount()-1))
							index=0;
						else 
							index=gallery.getSelectedItemPosition()+1;
					} 
					//改变gallery图片所选,自动触发ImageSwitcher的setOnItemSelectedListener 
					gallery.setSelection(index, true);
					return true; 
				} 
				return false; 
			}