我正在使用ViewPager在Android中实现一个滑块,我在每张幻灯片中都有一个VideoView,我在ViewPager的onPageSelected事件中播放视频。当我滑动时,我在VideoView中收到黑屏闪烁。这是我的activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/relativeLayout"
android:background="#3f444c">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/indicator"
/>
<SurfaceView
android:layout_width="0px"
android:layout_height="0px"
android:visibility="gone"/>
这是我的page.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#3f444c">
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainVideo"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="visible"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Your research on the go"
android:id="@+id/txtTitle"
android:textColor="#ffffff"
android:layout_below="@+id/mainVideo"
android:layout_centerHorizontal="true"
android:layout_marginTop="53dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Create a complete research library with article PDFs and attachments"
android:id="@+id/txtParagragh"
android:textColor="#ffffff"
android:layout_below="@+id/txtTitle"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAlignment="center" />
我也在这些链接中应用了解决方案:Dummy SurfaceView solution, Placeholder framelayout solution
没有什么对我有用,请帮助。