在渲染一个SurfaceView按钮 [英] Rendering a button over SurfaceView

查看:302
本文介绍了在渲染一个SurfaceView按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找对谷歌如何做到这一点,从我收集它不是123那样容易,因为表面观只是绘制了它上面,这人说的解决办法是使用一个XML布局并进行布局,然后添加表面观为孩子和按钮作为一个孩子了这一点。不过我完全在这个丢了,我真的很想看看如何做到这一点(我preFER看着实例和试错学习)一些code。

I've been looking on google on how to do this, from what I've gathered it's not as easy as 123 because the surface view will just draw above it, the solution which people have said is to use an xml layout and make a layout and then add the surface view as a child and the button as a child to that. However I'm completely lost on this I'd really love to see some code on how to do this (I prefer looking at examples and trial and error for learning).

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

我没有code中,除了你看到的XML是什么按钮添加(我已经做了很多试验和错误的)。

I've got no code for adding in the button except for what you see on the xml (I've been doing a lot of trial and error).

项目是这样的:活动 - >的setContentView(表面观) - >渲染上的onDraw

project works like this: activity --> setContentView(surface view) --> render the gfx on the onDraw

可有人请帮我这,有一次我已经看到了如何使用1对象做一个例子,我就可以与其他对象做到这一点。

Can someone please help me with this, once I've seen an example on how to do this with 1 object I'll be able to do it with other objects.

编辑 - 解决了它
好,我已经成功地从这个帖子 HTTP工作了:/ /www.mail-archive.com/android-beginners@googlegroups.com/msg11780.html

我必须设置的内容视图到XML文件,而一些结构添加到面视图,以便它会工作

I had to set the content view to the xml file, and add some constructs to the surface view so it would work

推荐答案

我不得不做类似的显示东西的的ImageView 过顶部的 SurfaceView ,并做了如下:

I had to do something similar to display an ImageView over-top of a SurfaceView, and did it as follows:

<?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的顶部。

This results in the button floating over top of the SurfaceView on the bottom-right corner.

这篇关于在渲染一个SurfaceView按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆