我在图库视图中有四张图片。当我们从左向右或从右向左滑动时,图库视图会移动所有图像,即如果我从第一张图像从左向右滑动,则它将移动到所有四张图像。 我想要的是,当我滑动它应该只移动到下一个图像。有人能让我知道在galleryview中这有什么可能吗?
答案 0 :(得分: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
答案 1 :(得分:0)
您可以考虑在其上使用带有手势的ViewFlipper,请看这个例子:
http://www.inter-fuser.com/2009/07/android-transistions-slide-in-and-slide.html
编辑:
哦,显然你应该实现手势检测,看一下这个问题/答案