【问题标题】:Rendering a button over SurfaceView在 SurfaceView 上渲染按钮
【发布时间】:2011-04-29 18:32:27
【问题描述】:

我一直在谷歌上寻找如何做到这一点,据我所知,它不像 123 那样简单,因为表面视图只会在它上面绘制,人们所说的解决方案是使用 xml 布局并进行布局,然后将表面视图添加为子视图,并将按钮添加为子视图。但是我对此完全迷失了,我真的很想看到一些关于如何做到这一点的代码(我更喜欢看例子和反复试验来学习)。

我的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<FrameLayout
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <Button
 android:id="@+id/Menu"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Menu" />
<Android.Game.GameView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"/>
</FrameLayout>
</LinearLayout>

除了您在 xml 上看到的内容外,我没有添加按钮的代码(我已经做了很多试验和错误)。

项目的工作方式如下:activity --> setContentView(surface view) --> 在 onDraw 上渲染 gfx

有人可以帮我解决这个问题吗,一旦我看到一个关于如何使用 1 个对象执行此操作的示例,我将能够使用其他对象执行此操作。

编辑 - 解决了 好的,我已经设法从这篇帖子 http://www.mail-archive.com/android-beginners@googlegroups.com/msg11780.html

中解决了

我必须将内容视图设置为 xml 文件,并向表面视图添加一些构造,以便它可以工作

【问题讨论】:

    标签: android surfaceview


    【解决方案1】:

    我必须做一些类似的事情来在SurfaceView 的顶部显示ImageView,并按如下方式进行:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff">
        <com.my.package.DrawingCanvas
        android:id="@+id/canvas"
        android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:focusable="true"
            android:background="#ffffff" />
        <RelativeLayout
            android:id="@+id/toolbar_notification"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:gravity="center_vertical">
            <ImageView
                android:id="@+id/toolbar_notification_icon"
                android:layout_width="40dp"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentTop="true"
                android:layout_alignParentRight="true"
                android:contentDescription="@string/content_desc_save_icon"
                android:gravity="center|center_vertical" />
        </RelativeLayout>
    </RelativeLayout>
    

    这会导致按钮浮在 SurfaceView 的右下角上方。

    【讨论】:

      猜你喜欢
      • 2014-03-28
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      • 1970-01-01
      • 2018-02-25
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多