title: How do i create a youtube view with fullscreen and portrait capabilities inside a container fragment view
body: <p>I have an activity and framelayout container for replacing fragments inside the activity.Like below</p>
  
  <pre><code>&lt;androidx.coordinatorlayout.widget.CoordinatorLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/rootCo_Ordinator_Layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#efefef"
      android:orientation="vertical"
      android:fitsSystemWindows="false"
      tools:context=".DetailsActivity"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;include layout="@layout/app_bar" /&gt;
  
          &lt;RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
  
              &lt;FrameLayout
                  android:id="@+id/container"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_above="@id/scroll_view_horizontal" /&gt;
  
  
              &lt;HorizontalScrollView
                  android:id="@+id/scroll_view_horizontal"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:fillViewport="true"
                  android:layout_above="@id/second_row"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_path"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:ellipsize="none"
                      android:padding="8dp"
                      android:scrollbars="horizontal"
                      android:singleLine="true"
                      android:textColor="@android:color/black"
                      android:textStyle="italic|bold"
                      tools:text="Sample Text" /&gt;
  
              &lt;/HorizontalScrollView&gt;
  
  
              &lt;LinearLayout
                  android:id="@+id/second_row"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_alignParentBottom="true"
                  android:background="#000000"
                  android:orientation="horizontal"
                  android:paddingBottom="4dp"
                  android:weightSum="5"&gt;
  
                  &lt;Button
                      android:id="@+id/btn_content"
                      style="@style/DetailButtonStyle"
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_gravity="center_horizontal"
                      android:layout_weight="1"
                      android:text="@string/btn_desc"
                      android:textAllCaps="false" /&gt;
  
                  &lt;Button
                      android:id="@+id/btn_sub_cat"
                      style="@style/DetailButtonStyle"
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_gravity="center_horizontal"
                      android:layout_weight="1"
                      android:text="@string/btn_cat"
                      android:textAllCaps="false" /&gt;
  
                  &lt;Button
                      android:id="@+id/btn_text"
                      style="@style/DetailButtonStyle"
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_gravity="center_horizontal"
                      android:layout_weight="1"
                      android:text="@string/btn_cmntry"
                      android:textAllCaps="false" /&gt;
  
                  &lt;Button
                      android:id="@+id/btn_video"
                      style="@style/DetailButtonStyle"
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_weight="1"
                      android:text="@string/btn_videos"
                      android:textAllCaps="false" /&gt;
  
                  &lt;Button
                      android:id="@+id/btn_image"
                      style="@style/DetailButtonStyle"
                      android:layout_width="0dp"
                      android:layout_height="match_parent"
                      android:layout_gravity="center_horizontal"
                      android:layout_weight="1"
                      android:text="@string/btn_images"
                      android:textAllCaps="false" /&gt;
              &lt;/LinearLayout&gt;
          &lt;/RelativeLayout&gt;
      &lt;/LinearLayout&gt;
  
      &lt;androidx.core.widget.ContentLoadingProgressBar
          android:id="@+id/details_loading"
          style="?android:attr/progressBarStyleLarge"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:background="@android:color/transparent" /&gt;
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>And i have another fragment that dynamically creates <strong>youtubeplayerview</strong> ,</p>
  
  <pre><code>&lt;ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/scroll_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fillViewport="true"
      android:fitsSystemWindows="false"
      android:scrollbars="vertical"&gt;
  
      &lt;LinearLayout
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/root_element"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:scrollbars="vertical"
          android:fitsSystemWindows="false"
          tools:context=".fragments.IntroFragment"&gt;
  
          &lt;include
              layout="@layout/empty_view"
              android:visibility="gone" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>I have FullScreen Util class like below</p>
  
  <pre><code>public class FullScreenHelper {
  
  private Activity context;
  private View[] views;
  
  public FullScreenHelper(Activity context, View ... views) {
      this.context = context;
      this.views = views;
  }
  
  public void enterFullScreen(View selectedView, View[] allViews) {
      View decorView = context.getWindow().getDecorView();
      hideSystemUi(decorView);
      for(View view : views) {
          if (!(view instanceof FrameLayout) &amp;&amp; (view != selectedView) ) {
              view.setVisibility(View.GONE);
              view.invalidate();
          }
      }
  
      for (View view:allViews){
          if (view != null &amp;&amp; (view != selectedView)  ){
              view.setVisibility(View.GONE);
              view.invalidate();
          }
      }
  }
  
  
  public void exitFullScreen(View selectedView, View[] allViews) {
      View decorView = context.getWindow().getDecorView();
  
      showSystemUi(decorView);
  
      for(View view : views) {
          view.setVisibility(View.VISIBLE);
          view.invalidate();
      }
  
      for (View view:allViews){
          if (view != null &amp;&amp; (view != selectedView)  ){
              view.setVisibility(View.VISIBLE);
              view.invalidate();
          }
      }
  }
  
  private void hideSystemUi(View mDecorView) {
      mDecorView.setSystemUiVisibility(
              View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                      | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                      | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                      | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                      | View.SYSTEM_UI_FLAG_FULLSCREEN
                      | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
  }
  
  private void showSystemUi(View mDecorView) {
      mDecorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
  }
  }
  </code></pre>
  
  <p>And i capture the toggle and make the changes in the Activity as such below,</p>
  
  <pre><code>  FullScreenHelper fsHelper = 
              new FullScreenHelper(this,mAppBar,mPathTextView,mHorizontalScrollView,mSecondRow);
  
         @Override
          public void toLandScape(View selectedView, View... allViews) {
                isLandscape = true;
                this.selectedView = selectedView;
                this.allViews = new View[allViews.length];
                this.allViews = allViews;
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                getSupportActionBar().hide();
                fsHelper.enterFullScreen(selectedView,allViews);
           }
  
           @Override
           public void toPortrait(View selectedView, View... allViews) {
                 isLandscape = false;
                 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                 getSupportActionBar().show();
                fsHelper.exitFullScreen(selectedView,allViews);
            }
  </code></pre>
  
  <p>There can be many <em>youtubeplayerviews</em> created dynamically in the fragment 
  I have added the respective listener when toggle screen is pressed.
  When user presses the toggle in the current view , <strong>the youtube-player should fill the screen and should hide all other views,
  and on pressing the toggle again should bring back the hidden views.</strong>
  But i am not able to achieve this .
  Currently all the views are getting hidden on landscape orientation changes,and show up all views on portrait.
  Any help in how i go about doing this would be highly appreciated.!!!</p>