2011-05-18 55 views
1

我在圖庫視圖中有四個圖像。當我們從左到右或從右到左滑動時,「圖庫視圖」會移動所有圖像,即如果從第一張圖像從左向右滑動,則會移至所有四張圖像。 我想要的是,當我滑動它應該只移動到下一個圖像。有人可以告訴我這是怎麼可能在galleryview?將Gallery視圖移動到Android中的一個滑動條上的下一個圖像?

+0

的可能的複製http://stackoverflow.com/questions/4311854/how-can-i-limit-fling-in-android-gallery-to-just - 一次一個項目每flling – 2012-02-27 20:29:35

回答

0

您可以考慮使用與它手勢ViewFlipper,看看下面這個例子:

http://www.inter-fuser.com/2009/07/android-transistions-slide-in-and-slide.html

編輯:

哦,很明顯你應該實現手勢檢測,採取的看看這個提問/回答

Fling gesture detection on grid layout

+0

不能我們控制在<圖片(XML文件) – bamini 2011-05-18 11:17:21

+0

它更容易使用這種方法imo,重寫標準畫廊的行爲可能是單調 – BFil 2011-05-18 11:53:23

+0

我在這個活動中添加回來和下一個按鈕,如果我按左邊的按鈕和右邊相應的圖片我需要show.i可以得到圖像名稱如何通過在圖庫適配器 – bamini 2011-05-19 06:06:28

1

我認爲你必須一起工作用手指滑動來改變圖像的手勢。對於下面的代碼可能對你有幫助。

 
import java.util.ArrayList; 
import android.app.Activity; 
import android.gesture.Gesture; 
import android.gesture.GestureLibraries; 
import android.gesture.GestureLibrary; 
import android.gesture.GestureOverlayView; 
import android.gesture.Prediction; 
import android.gesture.GestureOverlayView.OnGesturePerformedListener; 
import android.os.Bundle; 
import android.widget.Toast;

public class GesturesActivity extends Activity implements OnGesturePerformedListener { private GestureLibrary mLibrary;

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mLibrary = GestureLibraries.fromRawResource(this, R.raw.spells); 
    if (!mLibrary.load()) { 
     finish(); 
    } 

    GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures); 
    gestures.addOnGesturePerformedListener(this); 
} 

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 
    ArrayList<Prediction> predictions = mLibrary.recognize(gesture); 

    // We want at least one prediction 
    if (predictions.size() > 0) { 
     Prediction prediction = predictions.get(0); 
     // We want at least some confidence in the result 
     if (prediction.score > 1.0) { 
      // Show the spell 
      Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show(); 
     } 
    } 
} 

}

enter code here
+0

你在哪裏加載圖片? – bamini 2011-05-18 11:23:55

相關問題