0

私は人間のイメージを持っていて、イメージ上で右または左の手がクリックされたかどうかに応じて異なるサウンドを再生したいのですが、頭がクリックされた場合は 3 番目のサウンドを追加したいと思うかもしれません。これを行う簡単な方法はありますか? ?

4

2 に答える 2

1

レイアウトの背景として人間の画像を設定します。人間の画像に透明なボタンを配置します。たとえば、頭、左手、右手に透明なボタンを配置し、透明なボタンのボタンクリックリスナーを追加します。ボタンクリックリスナーで、必要なサウンドも再生します。これは、より単純なアプローチの1つです。

于 2011-09-14T22:14:51.597 に答える
1

最善の方法は、OnTouchEvent を使用し、getX() と getY() を使用することだと思います。これはそれをもう少しよく説明するのに役立つかもしれません

public boolean onTouch(View v, MotionEvent e) {
    // TODO Auto-generated method stub
    float x = e.getX();
    float y = e.getY(); 


    switch (e.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:

        if (x > 1 & x < 200 & y > 1 & y < 200) {
            ///Pretty much, what the X and Y are, are coordinates. 
                         soundPool.play(PLAY SOUND 1, 10, 10, 1, 0, 1);
                            ///I Use soundPool, but you could use whatever


////I think you'll have to figure out where each of the coordinates are at to the corresponding
 ///body part. E.G if the hand lies between (X= 220 to 240 and Y= 120 to 140) then 
///simply say: **(x >220 & x<240 & y >120 & y <140)**



}
        if (x > 1 & x < 200 & y > 200 & y < 400) {
            soundPool.play(PLAY SOUND 2, 10, 10, 1, 0, 1);

/// this is just another example of another set of coordinates.
        }

        break;

また、OnTouchListener を実装する必要があります。明らかに、これはコードの OnTouch 部分のみをカバーしており、残りは一目瞭然です (サウンドとビューを取得したと仮定すると)。これが役立つかどうか教えてください。神のご加護を!

于 2011-09-14T21:53:51.547 に答える