Android:表面视图

发布于 2025-01-02 19:25:40 字数 111 浏览 5 评论 0原文

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

未央 2025-01-09 19:25:41

SurfaceView 的设计目的不是与其他视图合成。如 setZOrderOnTop 的文档中所述,一次设置此模式后,SurfaceView 顶部将看不到任何其他窗口内容。

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

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.

來不及說愛妳 2025-01-09 19:25:41

根据我的经验,这仍然有效。
但如果你使用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的顶部......(我猜??)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文