【问题标题】:Android: SurfaceView安卓:SurfaceView
【发布时间】:2012-02-28 18:57:19
【问题描述】:

我有带有setZOrderOnTop(true) 的 SurfaceView。在绘图过程中透明 SurfaceView 的背景需要此标志。

如何在它前面显示任何视图?

【问题讨论】:

    标签: android surfaceview z-order


    【解决方案1】:

    SurfaceViews 不是为与其他视图复合而设计的。如setZOrderOnTop 的文档中所述,一旦设置此模式,SurfaceView 顶部将不会显示任何其他窗口内容。

    如果你想进行合成,你必须自己在屏幕外进行,然后将结果绘制到 SurfaceView 中。

    【讨论】:

    • 如何将结果绘制到 SurfaceView 中?
    【解决方案2】:

    根据我的经验,这仍然有效。 但是如果你使用RelativeLayout,它会很丑。

    <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>
    

    WallPaperService 使用 SurfaceView。 所以SurfaceView的顶部没有任何view不能上的理由……(我猜??)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      相关资源
      最近更新 更多