How can I set full screen to a VideoView without spawning a new activity in Android

Viewed 86

I have implemented an activity with VideoView layout that plays a livestream video.

I want to set a double click listener on that VideoView and make this VideoView play in full screen mode but without the need to start a new activity.

Is this possible or is it mandatory to launch an activity?

1 Answers

no, it`s not a mandatory to launch new activity.

For example in your double click method u can set orientation to landscape and dynamically change size of VideoView to make it fit whole screen.

It may look like this:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//this will get screen metrics
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;
//and then set it to your videoView
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoView.getLayoutParams();//it may be another layout params in tour case
params.height = displayHeight;
params.width = displayWidth;
videoView.setLayoutParams(params);
Related