surfaceView全屏和退出全屏

今天在闲暇时把视频如何全屏播放和如何退出全屏播放的问题给解决了一下。

全屏:

case R.id.screen:
					ViewGroup.LayoutParams lp = sv.getLayoutParams();
					
					lp.height = LayoutParams.MATCH_PARENT;
					
					lp.width = LayoutParams.MATCH_PARENT;
					System.out.println(lp.width);
					sv.setLayoutParams(lp);
					isbackPlay = true;
				break;


我给他加了一个按钮,来响应全屏事件。


然后捕捉back键的退出全屏:

@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub

	if(isbackPlay){
		if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getRepeatCount() == 0) {
			
			new AlertDialog.Builder(this).setIcon(R.drawable.wifi)
				.setTitle("您是否要退出全屏?")
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub					
						
						ViewGroup.LayoutParams	lp = sv.getLayoutParams();
						lp.width = LayoutParams.MATCH_PARENT;
						lp.height =380;
						sv.setLayoutParams(lp);
						isbackPlay = false;
					}
				}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						
					}
				}).show();
							
            return true;
        }
	}else{
		
	}
	
		
		return super.onKeyDown(keyCode, event);
	}

这样差不多实现全屏了,值得注意的是我设置的Boolean值isbackPlay可以考虑这里是什么意思!

你可能感兴趣的:(【android基础】)