2011-02-04 18 views
7

我創建了一個可滾動的圖像選擇器,但有一些信息要在每個圖像上顯示,而我的問題是,圖庫上有一個事件通知我圖像居中?滾動時應該發生此事件。「當圖像居中時」的圖庫事件

我的佈局是:

<Gallery android:id="@+id/coverflow" 
     android:layout_width="match_parent" android:layout_height="wrap_content" 
     android:layout_centerInParent="true" /> 
    <TextView android:id="@+id/author" android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:text="Titulo livro" 
     android:layout_above="@id/coverflow" android:gravity="center" /> 

    <ImageView android:id="@+id/div" android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:src="@drawable/library_div" 
     android:layout_above="@id/author" /> 

    <TextView android:id="@+id/title" android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:text="Author" 
     android:layout_above="@id/div" android:gravity="center" /> 
</RelativeLayout> 

我想,當滾動發生,新ITEN是中間的一個,筆者和標題TextViews得到更新。

任何提示?

回答

10

其實我發現:

coverflow.setCallbackDuringFling(true); 
     coverflow.setOnItemSelectedListener(new OnItemSelectedListener() { 
      @Override 
      public void onItemSelected(AdapterView<?> arg0, View arg1, 
        int arg2, long arg3) { 
       Toast.makeText(LibraryActivity.this, "SELECTING "+arg2, Toast.LENGTH_SHORT).show();    
      } 

      @Override 
      public void onNothingSelected(AdapterView<?> arg0) { 
       Toast.makeText(LibraryActivity.this, "NOTHING", Toast.LENGTH_SHORT).show();    
      } 
     }); 
+1

這很酷。謝謝! – 2011-02-04 15:07:37