0

我有一个人类的图像,我想根据在图像上单击右手还是左手来播放不同的声音,如果单击头部,我可能想添加第三个声音,有没有简单的方法可以做到这一点?

4

2 回答 2

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 回答
1

将人物图像设置为布局的背景。在人体图像上放置透明按钮,例如:在头部、左/右手上,并为透明按钮添加按钮单击侦听器。在按钮单击侦听器中也播放您想要的声音。这是更简单的方法之一。

于 2011-09-14T22:14:51.597 回答