【发布时间】:2017-06-13 17:28:08
【问题描述】:
我正在尝试将 youtube 播放器添加为双视图页面中的弹出窗口,但播放器会停止给出以下错误:
YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor android.support.v4.view.ViewPager{344132a VFED..... ........ 0,144-1080,1560 #7f0e00a1 app:id/pager_video}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: 1080, top: 809, right: -1080, bottom: 0 (these should all be positive).
和
YouTube video playback stopped because the player's view is not visible. The view android.widget.LinearLayout{36c8aa6 I.E...... ......ID 0,653-1080,1416 #7f0e009a app:id/video_box} has visibility "INVISIBLE".
我有三个 xml 文件:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
style="@style/customTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:elevation="@dimen/tiny_dimen" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
B.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs_video"
style="@style/customTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:elevation="@dimen/tiny_dimen" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager_video"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
C.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeToRefreshLayoutVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<SearchView
android:id="@+id/videoSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_video_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="vertical" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/video_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical"
android:visibility="visible">
<ImageButton
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onClickClose"
android:src="@android:drawable/btn_dialog" />
<fragment
android:id="@+id/video_fragment_container"
android:name="com.example.fragments.VideoFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
当我将 C 放入 A 中时,它可以正常工作,但是当我将 C 放入 A 中的 B 中时,它会出错。
附:这里 youtube com.example.fragments.VideoFragment 是 YouTubePlayerSupportFragment
【问题讨论】:
标签: android android-layout android-viewpager youtube-api android-youtube-api