Android-布局、表面视图和画布难题

Android-布局、表面视图和画布难题,android,layout,canvas,surfaceview,Android,Layout,Canvas,Surfaceview,在这里,我可能想一下子问得太多,但任何圣洁、耐心、安卓大师,只要能帮我一点忙,都有可能使我的项目免于失败 我正在开发一个化妆玩偶应用程序,用户可以在另一个视图中将物品从“服装库存”视图拖到“玩偶”视图 首先,我不知道如何将玩偶和库存放在不同的视图中,并且仍然能够在两者之间拖动位图。(位图的绘制和拖动本身不是问题) 到目前为止,我所能做的就是使用一个扩展的SurfaceView,通过编程将其添加到布局中,并使用一个线程将其绘制到画布上。在画布的一边,我画了组成娃娃的比特帕。另一方面,我绘制了构成清

在这里,我可能想一下子问得太多,但任何圣洁、耐心、安卓大师,只要能帮我一点忙,都有可能使我的项目免于失败

我正在开发一个化妆玩偶应用程序,用户可以在另一个视图中将物品从“服装库存”视图拖到“玩偶”视图

首先,我不知道如何将玩偶和库存放在不同的视图中,并且仍然能够在两者之间拖动位图。(位图的绘制和拖动本身不是问题)

到目前为止,我所能做的就是使用一个扩展的SurfaceView,通过编程将其添加到布局中,并使用一个线程将其绘制到画布上。在画布的一边,我画了组成娃娃的比特帕。另一方面,我绘制了构成清单的位图。它可以这样工作,但我需要能够将其拆分为两个视图,因为a)玩偶视图的高度需要大于库存视图的高度,以及b)我想在其他地方单独在不同的活动中重复使用这两个视图

最后,我的问题是:如何在两个曲面视图的画布之间共享位图?或者,我可以有一个覆盖整个屏幕的画布,上面有其他视图(按钮、文本视图等)?或者,有没有其他完全合乎逻辑的方式来做我正在尝试的事情,而这些方式我已经错过了?如果我有两个SurfaceView,每个画布都由一个线程控制,我将如何处理我正在拖动的位图可能同时部分“位于”两个画布区域的事实?(我真的只想要一块屏幕大小的画布,不是吗?)

编程添加的SurfaceView(我们称之为DollView)被添加到一个空的嵌套RelativeLayout中,如下面的布局XML所示。我继续不断地在布局XML中添加按钮,这些按钮以某种方式出现在DollView的顶部,并且不受DollView画布的连续绘制和重新绘制的影响。当我拖动一件衣服或玩偶的位图时,它会从这些按钮下面经过……如果我拖动的位图超出了玩偶视图父对象的指定宽度,我仍然可以“抓住”它,并将其带回视图中,但它不会被绘制到屏幕上。我也被这件事难倒了,虽然这是我目前最不关心的问题

我可以向任何对这种疯狂感兴趣的人展示他们想看的代码。谢谢你容忍我。我希望阅读它不会像试图解释它伤害了我一样伤害你的头!:)

以下是活动的布局,在OnCreate中设置为内容视图:

<?xml version="1.0" encoding="utf-8"?>



对于2D游戏,我强烈建议使用AndEngine。它是免费使用的,当你准备好在市场上出售游戏时,没有什么可担心的。该项目是开源的,但只需使用他们的编译库就可以快速开始使用它

对于显示演示的视频:

支持论坛:

开始使用andEngine:

最初使用它需要一些工作,但一旦你了解了基本知识,它的使用就令人难以置信了。

你可以尝试使用它将按钮覆盖到你的SurfaceView上。不确定您的单击是否会发送到正确的视图


使用FrameLayout在图像上叠加文本的方法。

最好的方法是将surfaceview添加为RelativeLayout的子级。那么另一个视图将是RelativeView的另一个子视图。这样就不会干扰画布的绘制


好的,谢谢,我一定会仔细阅读的。然而,这是我非常想为自己做和理解的事情(除了呼救这一问题):)此外,我的应用程序中没有足够的“游戏”需要引擎。只有一个屏幕,您可以在其中移动图像。谢谢。我能做些什么让这个问题更清楚吗?我真的很难过在这里需要帮助:)
 <TextView android:id="@+id/header_text" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:text="Header text..." />

<!-- The extended SufaceView (DollView) is programatically added to this RelativeLayout -->
<RelativeLayout android:id="@+id/doll_layout"
    android:layout_width="350dip"
    android:layout_height="wrap_content"
    android:layout_below="@+id/header_text"
    android:layout_alignParentLeft="true" />

<TextView android:id="@+id/stats" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_below="@+id/header_text"
    android:layout_toRightOf="@+id/doll_layout"
    android:layout_alignParentRight="true"
    android:text="Stats text..." />     

<TableLayout android="@+id/stats_table"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/stats"
    android:layout_toRightOf="@+id/doll_layout"
    android:layout_alignParentRight="true">

<TableRow>
<TextView android:id="@+id/stat_one" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:text="stat one..." />

<TextView android:id="@+id/stat_one_score" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="0" />

<TextView android:id="@+id/stat_one_mod" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:text=" " />

</TableRow>
<TableRow>
<TextView android:id="@+id/stat_two" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:text="stat two..." />

<TextView android:id="@+id/stat_two_score" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="0" /> 

<TextView android:id="@+id/stat_two_mod" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:text=" " />
</TableRow>

<TableRow>
<Button android:id="@+id/stats_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="stats" />

<Button android:id="@+id/info_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="info" />

<Button android:id="@+id/help_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="help" />
</TableRow>
</TableLayout>

<!-- A "dragged" bitmap from the DollView passes underneath this TextView.  Why? -->
<TextView android:id="@+id/doll_name"
    android:textSize="16sp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/header_text"
    android:layout_alignParentLeft="true"
    android:text="" />

<!-- dragged bitmaps pass under all of these buttons too, apart from the last three
     nav buttons, as they're outside the DollView's width. 
     How would I make the dragged bitmaps pass OVER these objects, instead? --> 
<Button android:id="@+id/nav_btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/nav_btn2"
    android:text="nav1" />

<Button android:id="@+id/next_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/nav_btn1"
    android:layout_centerHorizontal="true"
    android:text="Next" />

<Button android:id="@+id/prev_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/nav_btn1"        
    android:layout_toLeftOf="@+id/next_btn"
    android:text="Previous" />

<Button android:id="@+id/nav_btn2" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/nav_btn3"
    android:text="nav2" />

<Button android:id="@+id/nav_btn3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/nav_btn4"
    android:text="nav3" />      

<Button android:id="@+id/nav_btn4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/nav_btn5"
    android:text="nav4" />

<Button android:id="@+id/nav_btn5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/nav_btn6"
    android:text="nav5" />

<Button android:id="@+id/nav_btn6" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="nav6" />
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

    layout = new RelativeLayout(this);
    RocketView rocketView;
    rocketView = new RocketView(this);
    layout.addView(rocketView);
    setContentView(layout);
}