0

I have a VideoView inside a xml which is inside a different xml

<main.xml
    <include layout = "@layout/subLayou1"/> >
</main>

<subLayout1.xml
    <include layout = "@layout/subLayout2"/> >
</subLayout1>

<subLayout2.xml
    <VideoView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:background="@android:color/transparent" />

    <Button  for full screen />
</subLayout2>

but i want this videoview in subLayout2 to take full-screen when a full screen button is clicked.. please help me out!!

Adithya.K
  • 303
  • 2
  • 15

1 Answers1

0

In your code you have put the following width height for sublayout

android:layout_width="match_parent"
android:layout_height="match_parent"

Sublayout1 just includes sublayout2. You need to specify certain width and height other than wrap_content and match_parent.

Then in the java file for this activity:

VideoView vv = findViewById(R.id.videoView);
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
         android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();


    fullscreenbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            params.width =  metrics.widthPixels;
            params.height = metrics.heightPixels;
            vv.setLayoutParams(params);
        }
    });

For setting the video back to original:

    normalscreenbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            params.width =  (int) (original_width_dp*metrics.density);
            params.height = (int) (original_height_dp*metrics.density);
            vv.setLayoutParams(params);
        }
    });

During fullscreen you find the value of the screensize and then set it to the videoview. On minimize you have to set the value back to the original. metrics.density converts dp into pixels.

Reference

Community
  • 1
  • 1
suku
  • 10,507
  • 16
  • 75
  • 120