8
मैं किसी भी दृश्य को मैन्युअल रूप से निर्दिष्ट किए बिना किसी गतिविधि के सभी दृश्यों (समूह देखें) में एक जेस्चरडेटेटर जोड़ना चाहता हूं। अभी ऑनफ्लिंग() पृष्ठभूमि पर स्वाइप करते समय सक्रिय होता है लेकिन जब स्वाइप नहीं होता है Button1।सभी बच्चे के विचारों के लिए जेस्चरडेक्टर सेट करें
package com.app.example;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class ExampleActivity extends Activity {
Context mContext = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
LinearLayout parent = new LinearLayout(mContext);
parent.setOrientation(LinearLayout.VERTICAL);
parent.setBackgroundColor(Color.RED);
Button button1 = new Button(mContext);
button1.setText("Button 1");
Button button2 = new Button(mContext);
button2.setText("Button 2");
parent.addView(button1);
parent.addView(button2);
final GestureDetector gestureDetector = new GestureDetector(
new MyGestureDetector());
parent.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
gestureDetector.onTouchEvent(event);
return true;
}
});
setContentView(parent);
}
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
// right to left
if(e1.getX() - e2.getX() > 10 && Math.abs(velocityX) > 20) {
Log.i("onFling", "right to left");
return false;
// left to right
} else if (e2.getX() - e1.getX() > 10 && Math.abs(velocityX) > 20) {
Log.i("onFling", "left to right");
return false;
}
return false;
}
}
जेस्चरऑवरलेव्यू टिप के लिए धन्यवाद। इसे इस्तेमाल करने में मुझे कुछ समय लगा -> http://www.vogella.com/articles/AndroidGestures/article.html – Paradiesstaub
खुशी है कि मैं मदद कर सकता हूं :) – Angelo
मैं जानना चाहता हूं कि इसका उपयोग किए बिना इसे कैसे करना है GestureOverlayView। – halxinate