2011-01-08 70 views
2

我可能试图在这里一次问太多,但任何圣洁,耐心的Android大师谁可以帮我一点点,可能会从我的项目拯救失败。Android - 一个布局,表面视图和帆布难题

我正在制作一个装扮娃娃应用程序,用户可以在另一个视图中将物品从“服装库存”视图拖到“娃娃”视图。首先,我不知道如何在不同的视图中使用玩具娃娃和库存,并且仍然能够在两者之间拖动位图。 (绘制和拖动位图本身不是问题)。

到目前为止,我所能得到的所有工作都是使用一个扩展的SurfaceView,我将其编程添加到我的布局中,并使用线程绘制到其Canvas。在画布的一边,我画了组成玩偶的bitmpas。另一方面,我绘制了构成库存的位图。它可以很好地工作,但我需要能够将它分成两个视图,因为a)玩偶视图的高度需要大于库存视图的高度,并且b)我想重新使用在其他地方的两种意见,在不同的活动中。

因此,最后,我的问题是:如何在两个表面视图的Canvases之间共享位图?或者,我可以有一个画布覆盖整个屏幕上的其他视图(按钮TextView等)放在它的顶部?或者,有没有其他更合乎逻辑的方式去做我试图通过我的东西?如果我有两个SurfaceView,每个都有一个由线程控制的Canvas,那么我将如何处理这一事实:我拖动的位图可能同时部分地“在”Canvases的两个区域“内部”? (我真的只想要一个屏幕大小的画布,不是吗?)

根据下面的Layout XML,我们将它称为DollView的主动添加的SurfaceView添加到一个空的嵌套RelativeLayout。我继续通过将Button添加到布局XML来不断改进事物,这些XML以某种方式出现在DollView之上,并且不受持续绘制和重新绘制DollView画布的影响。当我拖动服装物品或玩偶片的位图时,它会在这些按钮下面传递... 如果我在DollView的父亲RelativeLayout的指定宽度外拖动位图,我仍然可以“保留”它,它回到了视野,但它并没有画在屏幕上。完全被这个难住了,尽管这是我现在问题最少的问题。

我可以显示任何对这种疯狂感兴趣的人,尽可能多的代码,因为他们希望看到。感谢您的支持。我希望阅读它不会像解释它伤害我的一样伤害你的头。 :)

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

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

<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" /> 

+0

有什么我可以做,使这个问题更清楚了吗?我真的很伤心在这里得到一些帮助:) – JimBadger 2011-01-10 09:54:22

回答

1

最好的方法是将你的Surfaceview添加为RelativeLayout的一个子元素。那么另一个视图将成为RelativeView的另一个孩子。这样画布画就不会受到干扰。

http://groups.google.com/group/android-developers/browse_thread/thread/b3917e04d47fb27f?pli=1

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); 
} 
0

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

用于显示演示的视频,因为他们的支持论坛 http://www.andengine.org/blog/

http://www.andengine.org/forums/

入门andEngine: http://www.andengine.org/forums/tutorials/getting-started-with-andengine-t11.html

这将是一个有点工作,为您最初使用它,但一旦你知道基础知识,它使用起来非常神奇。

+0

嗯,谢谢,我一定会详细阅读。然而,这是我非常想做的事情,并为自己理解(除了这个问题的求助呼吁外):) 此外,我的应用中没有足够的“游戏”需要引擎。只需一个屏幕即可移动图像。 虽然,赞赏。 – JimBadger 2011-01-08 21:49:53