SurfaceView全屏播放问题解决方案

已测试通过可实现全屏退出全屏,直接贴代码了:

private ViewGroup.LayoutParams mrLayoutParams; //默认布局
private boolean isbackPlay = false;








mSurfaceView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if(isbackPlay){
                        new AlertDialog.Builder(VideoActivity.this)
                                .setTitle("您是否要退出全屏?")
                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        // TODO Auto-generated method stub
                                        mSurfaceView.setLayoutParams(mrLayoutParams);
                                        isbackPlay = false;
                                    }
                                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub

                            }
                        }).show();
                    }else{
                        LogPlus.e("全屏播放");
                        mrLayoutParams = mSurfaceView.getLayoutParams();
                        mSurfaceView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT));
                        isbackPlay = true;
                    }
                    return true;
                }
                return false;
            }
        });
 

你可能感兴趣的:(Android)