【问题标题】:Android clickable areas in image [closed]图像中的Android可点击区域[关闭]
【发布时间】:2011-09-14 21:18:34
【问题描述】:

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

【问题讨论】:

    标签: android image clickable


    【解决方案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 部分,其余部分应该是不言自明的(假设您听到了声音并向下查看)。 让我知道这是否有帮助。上帝保佑!

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-12
        • 2015-12-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多