Reputation: 833
I am working on one custom video player in android. I am using VideoView for playing video. Initially my VideoView will be of some size (lets say size = (width , height) = (400, 300)). One of the control button of my custom video view is "Expand/Collapse". After clicking on "Expand/Collapse" button, I want to set VideoView size to fullscreen(means device's full screen size) if current VideoView size is of Inline and vice versa(from full screen to Inline also).
Do anybody know the proper way to do the above task?
Upvotes: 3
Views: 11694
Reputation: 3666
First of all, you got guts to ask a Android question and have a iOS logo ;) (kidding)
But, I think you can use this:
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
params.width = metrics.widthPixels;
params.height = metrics.heightPixels;
params.leftMargin = 0;
videoView.setLayoutParams(params);
and to set it back:
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
params.width = (int) (400*metrics.density);
params.height = (int) (300*metrics.density);
params.leftMargin = 30;
videoView.setLayoutParams(params);
I assume that you know how to make a OnClickListener
.
I got the information here: VideoView Full screen in android application
Edit1
I can think of 2 things quickly.
1. Add this: getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
2. or try this:
YourButton.setVisibility(View.GONE);
or
YourButton.setVisibility(View.INVISIBLE);
Upvotes: 10