2011-09-14 27 views
0

私は人間のイメージを持っています。画像上で右手または左手がクリックされたかどうかによって異なる音を出そうとしています。頭がクリックされると、これを行う簡単な方法はありますか?画像内のクリック可能な領域

答えて

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部分だけをカバーしており、残りの部分はかなり自明であるはずです(あなたがサウンドを持っていて、ビューを見ていると仮定します)。 これが役立つかどうかお知らせください。神のご加護を!

1

レイアウトの背景として人間の画像を設定します。 人の画像に透明ボタンを置く:例えば、頭の上、左/右の手、透明ボタン用のボタンクリックリスナーを追加する。 ボタンクリックリスナーでも、あなたが望むサウンドを再生します。 これは簡単なアプローチの1つです。

関連する問題