Android: SurfaceView

空扰寡人 提交于 2020-02-06 06:24:44

问题


I have SurfaceView with setZOrderOnTop(true) .This flag is needed for the transparent SurfaceView's background during the drawing process.

How can I display any View in front of it?


回答1:


SurfaceViews are not designed to be composited with other views. As described in the doc for setZOrderOnTop, once you set this mode, none of the other window contents will be visible on top of the SurfaceView.

If you want to do compositing, you will have to do it yourself, off-screen, then draw the results into the SurfaceView.




回答2:


In my experience, that still work. But if you use a RelativeLayout, it will be ugly.

<FrameLayout 
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.applicationtest.MainActivity" >
    <SurfaceView
        android:id="@+id/surfaceView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>
    <LinearLayout
        android:layout_marginTop="50sp"
        android:orientation="vertical"
        android:background="#44444444"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <TextView
            android:text="ttttttttttttttttttttt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:text="ttttttttttttttttttttt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:text="ttttttttttttttttttttt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</FrameLayout>

The WallPaperService are usung SurfaceView. So there is no reason that no view can't be on the top of SurfaceView...(I guess??)



来源:https://stackoverflow.com/questions/9174712/android-surfaceview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!