问题描述:

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;
}
相关阅读:
Top