Android关于含有SurfaceView的View会导致其他空间出问题的解决方案

今天写游戏的时候碰到一个非常诡异的问题,之前我的游戏GameView是继承自View的,当是View时没有一点问题

但是后来为了能够让画面流畅,我就把View换成了带有双缓冲机制的SurfaceView了,这时候问题就出现了,原本显示在

SurfaceView上层的一个Button绘制的时候绘制不全了,如下图:


看图片左下方的一个方向按钮,显示不全了,这个方向按钮放在一个RelativeLayout中,该RelativeLayout放在SurfaceView上层。具体布局文件如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="#000000" >
	
    <com.oysb.rpg.GameView
        android:id="@+id/game_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">        
    </com.oysb.rpg.GameView>
    
    <RelativeLayout
        android:background="#01000000"
        android:id="@+id/relative_dir"
        android:layout_width="200px"
        android:layout_height="200px"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >

        <ImageView
            android:layout_width="100px"
            android:layout_height="100px"
            android:layout_centerInParent="true"
            android:src="@drawable/btn_direction_bg" />

        <ImageView
            android:id="@+id/img_dir"
            android:layout_width="100px"
            android:layout_height="100px"
            android:layout_centerInParent="true"
            android:src="@drawable/btn_direction" />
    </RelativeLayout>

</RelativeLayout>


百思不得其解为什么会少一块,后来发现为RelativeLayout加上一个background属性后发现图片显示全了,但是加上background属性后会使得游戏界面不美观,后来

无奈之下设置background="#01000000"设置一个肉眼看不出来的颜色,来达到来图片显示完全的目的。

这回方向控制按钮的图片显示完全了:


虽然搞不清楚确切的原因,但是我猜想这和surfaceview的机制有关,以前当游戏层用view时不会出现这种问题,我在想,是不是当View中含有surfaceView时是不是在

绘图的时候进行什么优化处理,优化的手段就是当前区域颜色为透明的时候就不写入屏幕的绘制缓冲区中,导致图片绘制不全?

以上博客只是记录一下问题,如果有哪位高人知道是什么原因,恳请指教~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值