2

ここで一度に多くのことを尋ねようとしているのかもしれませんが、少しでも私を助けてくれる聖人で忍耐強い Android の第一人者は、おそらく私のプロジェクトを失敗から救ってくれるでしょう。

私は、ユーザーが別のビューで「衣類の在庫」ビューから「人形」にアイテムをドラッグできる着せ替え人形アプリに取り組んでいます。

まず、人形とインベントリを別々のビューに表示し、2 つの間でビットマップをドラッグする方法がわかりません。(ビットマップの描画とドラッグ自体は問題ではありません)。

これまでのところ、拡張された SurfaceView を 1 つ使用するだけで作業できました。これをプログラムでレイアウトに追加し、スレッドを使用してキャンバスに描画します。キャンバスの片側に、人形を構成するビットパスを描きます。一方で、インベントリを構成するビットマップを描画します。そのようにうまく動作しますが、2 つのビューに分割できるようにする必要があります。a) 人形ビューの高さは在庫ビューの高さよりも大きくする必要があり、b) を再利用したいからです。別の場所にある 2 つのビューは、それぞれ別のアクティビティにあります。

最後に、私の質問は次のとおりです。2 つのサーフェス ビューのキャンバス間でビットマップを共有するにはどうすればよいですか? または、他のビュー (Buttons TextView など) をその上に配置して画面全体をカバーする Canvas を使用できますか? または、私が試みていることを行うための他の完全に論理的な方法があり、それは私を通り過ぎましたか? 2 つの SurfaceView があり、それぞれがスレッドによって制御されている Canvas を持っている場合、ドラッグしているビットマップが部分的に両方の Canvas の領域の「内側」に同時に入る可能性があるという事実をどのように処理しますか? (私は本当に 1 つの画面サイズの Canvas が欲しいだけですよね?)

プログラム的に追加された SurfaceView (DollView と呼びましょう) は、以下の Layout XML に従って、空のネストされた RelativeLayout に追加されます。私はレイアウト 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" />

4

3 に答える 3

1

FrameLayout を使用してボタンをSurfaceViewに重ねることができます。クリックが正しいビューに送信されるかどうかはわかりません。

Romain Guy には、FrameLayout を使用して画像にテキストを重ねる例があります。

于 2011-01-29T02:06:47.773 に答える
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);
}
于 2011-03-05T11:27:53.353 に答える
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

初めて使うのは少し大変ですが、基本を知ってしまえば驚くほど便利です。

于 2011-01-08T21:39:05.030 に答える