2011-12-01 64 views
2

我有一個帶有箭頭指示的畫廊,顯示左側或右側是否有圖像。Android - Gallery.onItemSelected()導致滾動以捕捉到

 <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/black" 
     android:layout_weight="1" > 
      <com.package.views.MyGallery 
      android:id="@+id/carGallery" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:spacing="2dip" 
      android:fadingEdge="none" /> 
      <ImageView 
      android:id="@+id/prev" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:src="@drawable/left_orange_arrow" 
      android:paddingLeft="25dip" /> 
      <ImageView 
      android:id="@+id/next" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_alignParentRight="true" 
      android:src="@drawable/right_orange_arrow" 
      android:paddingRight="25dip" /> 
     </RelativeLayout> 

我更新的箭頭這樣:

carGallery.setOnItemSelectedListener(new OnItemSelectedListener(){ 
    @Override 
    public void onItemSelected(AdapterView<?> adapter, View view, final int position, long id) { 
     Car car = carAdapter.getCar(position); 
     top.setText(car.nickname); 
     bottom.setText(car.year+" "+car.make+" "+car.model); 

     if(carAdapter.getItems().size() == 1) { 
      prev.setVisibility(View.GONE); 
      next.setVisibility(View.GONE); 
     } 
     else if(position == 0) { 
      prev.setVisibility(View.GONE); 
      next.setVisibility(View.VISIBLE); 
     } 
     else if(position == carAdapter.getItems().size()-1) { 
      prev.setVisibility(View.VISIBLE); 
      next.setVisibility(View.GONE); 
     } 
     else { 
      prev.setVisibility(View.VISIBLE); 
      next.setVisibility(View.VISIBLE); 
     } 
    } 
}); 

任何時候,我改變箭頭的知名度,畫廊捕捉到剛剛滾動到選擇的項目。我知道Gallery.onItemSelected()會導致捕捉,因爲當我執行Gallery.setCallbackDuringFling(false)時,它不會在捕捉到最後一個項目之前進行捕捉。

我能做些什麼來阻止Gallery像這樣捕捉?

在此先感謝!

回答