当前位置: 动力学知识库 > 问答 > 编程问答 >

android - move the image according to trackball

问题描述:

Hi i want to move the image left right,down,up directions according to track ball .for this please give me the some code suggestions.Thanks in advance

网友答案:

Haven't done anything exactly like that before, but I certainly have detected trackball presses for some of my projects, to detect up,down,left right is very similar, so you just need to move your image on the event.. Hope this is of use:

public boolean onKeyDown(int keyCode, KeyEvent event) {    
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_UP : 
        // code to move image up
        break;
    case KeyEvent.KEYCODE_DPAD_DOWN : 
        // code to move image down
        break;
    case KeyEvent.KEYCODE_DPAD_LEFT : 
        // code to move image left
        break;
    case KeyEvent.KEYCODE_DPAD_RIGHT : 
        // code to move image right
        break;            
    }
    return false;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: