0

我有一个活动和框架布局容器,用于替换活动内的片段。如下所示

<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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <include layout="@layout/app_bar" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <FrameLayout
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/scroll_view_horizontal" />


            <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">

                <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" />

            </HorizontalScrollView>


            <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">

                <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" />

                <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" />

                <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" />

                <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" />

                <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" />
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>

    <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" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

我还有另一个动态创建youtubeplayerview的片段,

<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">

    <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">

        <include
            layout="@layout/empty_view"
            android:visibility="gone" />
    </LinearLayout>
</ScrollView>

我有如下 FullScreen Util 类

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) && (view != selectedView) ) {
            view.setVisibility(View.GONE);
            view.invalidate();
        }
    }

    for (View view:allViews){
        if (view != null && (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 && (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);
}
}

我捕获切换并在 Activity 中进行如下更改,

  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);
          }

在按下切换屏幕时,我添加了相应的侦听器的片段中可以动态创建许多youtubeplayerviews 。当用户在当前视图中按下切换按钮时,youtube 播放器应该填满屏幕并隐藏所有其他视图,再次按下切换按钮应该带回隐藏的视图。 但我无法做到这一点。目前,所有视图都在横向更改时隐藏,并在纵向显示所有视图。对我如何做这件事的任何帮助将不胜感激。!!!

4

1 回答 1

0

去任何 youtube 视频

https://www.youtube.com/watch?v=m8ZoxzX0hro       #this is how the url looks 

现在为了使其全屏并在您的应用程序中使用它,您必须更改 url 说

https://www.youtube.com/embed?v=m8ZoxzX0hro 

watch 已被 embed 取代

于 2019-05-16T08:03:38.570 回答