概述
网上提供了很多关于SurfaceView闪屏的解决办法,但是有的可以,有的不可以,下面是关于我在项目中出现的SurfaceView闪屏解决办法。期间遇到三个问题
我的项目是在Listview中嵌入视频列表播放器,所以在Listview的Item布局中定义了SurfaceView,如下:
问题一:闪屏
<FrameLayout
android:layout_width="match_parent"
android:layout_height="202dp"
android:id="@+id/lay_min_video"
android:background="#000000"
android:layout_gravity="center_horizontal">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/min_video_view"
android:layout_gravity="center"
android:background="#00000000"/>
<ImageView
android:id="@+id/min_video_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
<ImageView
android:id="@+id/play_controll"
android:layout_width="55dip"
android:layout_height="55dip"
android:scaleType="fitXY"
android:layout_gravity="center"
android:src="@drawable/play_minvideo_play_button"/>
<ProgressBar
android:id="@+id/video_bar"
android:layout_width="50dp"
android:layout_height="50dp"
style="@android:style/Widget.ProgressBar"
android:indeterminateDrawable="@drawable/thailand_video_progressbar_bg"
android:layout_gravity="center"
android:visibility="gone" />
<ProgressBar
android:id="@+id/video_progress"
android:layout_width="match_parent"
android:layout_height="3dp"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/thailand_progress_bg"
android:layout_gravity="bottom"
android:visibility="gone"/>
</FrameLayout>
但是每次进入都会出现闪屏,我得解决办法是需要两步:
第一步:和部分网友提供的答案一样,在定义Listview的布局文件最底层添加一个宽高为0dp的SurfaceView,如图:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/activity_layout_bg">
<SurfaceView
android:layout_width="0dp"
android:layout_height="0dp" />
<com.lgshouyou.vrclient.thailand.MyListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/common_listview"
android:verticalSpacing="1dp"
android:listSelector="@color/transparent_color"
android:scrollbars="none"/>
</FrameLayout>
但是只是实现这一步并不能解决问题,不是必出但是偶尔还是会出现闪屏,没办法就试着在Activity中添加
第二步:getWindow().setFormat(PixelFormat.TRANSPARENT);
之后就没出现闪屏了。
问题二:占用其他布局
因为我的视频播放列表是在Fragment中定义的,所以在Fragment之间切换会出现一种现象,正在播放视频的播放器模块item占用了的其他布局,如图所示,图一是上滑之前的正在播放的视频item,图二是上滑一部分切换Fragment之后,在切回来之后的效果,可以看到上滑一部分后切换Fragment,可以看到部分标题栏的界面被SurfaceView穿透,解决办法就是将SurfaceView的背景设置为透明,有时会占用整个标题栏目
问题三:挖空底部布局
有时首次进入或者home键之后会在SurfaceView渲染好之前,会把Activity挖空,露出底下的Activity的内容,以上第一个问题可以解决首次挖空问题,home键之后这种问题可以通过上面覆盖一个ImageView解决,这种问题都是由于SurfaceView在渲染的时候应该是将所有在它下面的全部View都“挖空”,然后渲染自己。
最后
以上就是留胡子老鼠为你收集整理的android 布局文件定义的SurfaceView闪屏,挖空布局,以及占用其他布局等问题解决办法的全部内容,希望文章能够帮你解决android 布局文件定义的SurfaceView闪屏,挖空布局,以及占用其他布局等问题解决办法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复