2011-04-29 106 views
1

我一直在关注如何做到这一点,从我所收集的信息来看,它不像123那么容易,因为表面视图只会在它上面绘制,人们说的解决方案是使用xml布局并进行布局,然后将该表面视图添加为子项,并将按钮添加为该子项。然而,我完全失去了这一点,我真的很想看到如何做到这一点的代码(我喜欢看例子和试验和错误的学习)。在SurfaceView上渲染按钮

我的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内容(我已经做了很多尝试和错误的)。

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

是否有人可以帮助我,一旦我已经看到了如何做榜样这与1对象,我将能够做到与其他对象。

编辑 - 解决它 好,我已经成功地从这个岗位工作了http://www.mail-archive.com/[email protected]/msg11780.html

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

回答

0

我不得不做一些类似显示ImageView过顶一个SurfaceView的事情,而且做得如下:

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