我尝试为youtube player view
设置触摸列表显示功能,该功能可以检测视频上的触摸,但是不能,当我按视频上的任何内容时都没有改变。
我在Google中搜索,但找不到很好的答案。
这是我的代码:
xml文件:
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="410px"
android:layout_below="@+id/progressBar"
android:paddingTop="5dp"
android:layout_weight="0.96"
android:clickable="true"
/>
以及此处的java文件:
final YouTubePlayerView youtubePlayer = (YouTubePlayerView) findViewById(R.id.youtube_player_view);
youtubePlayer.setVisibility(View.GONE);
youtubePlayer.setOnTouchListener(new OnTouchListener() {//set swipe setting for small screen in left bottom corner
int downX, upX, downY, upY;
int move=0;
@Override
public boolean onTouch(View v, MotionEvent event) {
if (video_full_sc==0){
if (event.getAction() == MotionEvent.ACTION_DOWN) { //the swipe start
downX = (int) event.getX();
downY = (int) event.getY();
Log.i("event.getX()", " downX " + downX);
return false;
}
else if (event.getAction() == MotionEvent.ACTION_UP) { //the swipe ended
upX = (int) event.getX();
upY = (int) event.getY();
Log.i("event.getX()", " upX " + upX);
if (downY - upY > 100 && history[pages_hi_n - 1] == 1) {// swipe up
webview2.setVisibility(View.VISIBLE);
//videoWebView.setVisibility(View.GONE);
myWebView.setVisibility(View.GONE);
history[pages_hi_n] = 2;
pages_hi_n++;
state = 2;
ViewGroup.LayoutParams newParams = youtubePlayer.getLayoutParams();
RelativeLayout.LayoutParams layoutParams1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 410);
layoutParams1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
layoutParams1.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
layoutParams1.topMargin = 0;
layoutParams1.leftMargin = 0;
youtubePlayer.setLayoutParams(layoutParams1);
small_v = 0;
ImageButton fsBtn = (ImageButton) findViewById(R.id.fsButton);
fsBtn.setVisibility(View.VISIBLE);
} else if (upX - downX > 100) { // swipe right
if (small_v == 1) {
//get size of screen
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
final int height = displayMetrics.heightPixels;
final int width = displayMetrics.widthPixels;
//animation
animateScroll(0, (int) width);
//videoWebView.onPause();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//hide video
//WebView videoWebView = (WebView) findViewById(R.id.videoWebView);
youtubePlayer.setVisibility(View.GONE);
//back video (it hide....)
animateScrol2(width, 0);
}
}, 701);
}
} else if (upY - downY > 100 && history[pages_hi_n - 2] == 1) {// swipe down
webview2.setVisibility(View.GONE);
myWebView.setVisibility(View.VISIBLE);
history[pages_hi_n] = 0;
pages_hi_n--;
state = 1;
double widthV = widthScreen / 1.86;
double heightV = heightScreen / 5;
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams((int) widthV, (int) heightV);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.bottomMargin = 150;
youtubePlayer.setLayoutParams(layoutParams);
small_v = 1;
ImageButton fsBtn = (ImageButton) findViewById(R.id.fsButton);
fsBtn.setVisibility(View.GONE);
if (alr_bac_fr_1 == 1) { //need go back in mywebview
myWebView.goBack();
}
alr_bac_fr_2 = 1;
}
return false;
}
}
return false;
}
});
此代码未返回任何内容。 对不起,我的英语不好,非常感谢!