YoutubePlayerFragment
클래스를 사용하여 동영상을 재생하고 있습니다. GestureListener
을 추가하고 싶지만 제스처 감지기를 설정할 방법이 없습니다. 나는 시도 :제스처 감지기를 YoutubePlayerFragment로 설정하는 방법
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:id="@+id/player_holder"
android:visibility="gone"
android:layout_weight="40">
<RelativeLayout
android:layout_width="match_parent"
android:duplicateParentState="true"
android:layout_height="match_parent">
<fragment
android:id="@+id/player_fragment"
android:duplicateParentState="true"
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/gestureCatcher"
android:orientation="vertical"
android:duplicateParentState="true"
android:layout_height="match_parent" />
</RelativeLayout>
</LinearLayout>
및
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
class MyGestureDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(NonStopActivity.this, "Left Swipe", Toast.LENGTH_SHORT)
.show();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(NonStopActivity.this, "Right Swipe", Toast.LENGTH_SHORT)
.show();
}
} catch (Exception e) {
// nothing
}
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
}
를이 내가있는 LinearLayout
gestureDetector = new GestureDetector(this, new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};
LinearLayout gestureCatcher = (LinearLayout) findViewById(R.id.gestureCatcher);
gestureCatcher.setOnTouchListener(gestureListener);
그러나 오버레이 블록 YoutubePlayerFragment
에 동작 감지기를 설정하는 방법입니다. 이 문제를 해결할 수있는 해결책이 있습니까?