开发者

Android Button getX()

I'm trying to call getX() on a button, but eclipse is telling me there's no such method for button objects. In fact, it's telling me there's no getX() for Views either, which baffles me because the API says there are. Code:

public boolean onTouch(View arg0, MotionEvent arg1) {
    int touchX = (int)arg1.getX();
    int touchY = (int)arg1.getY();
    int tI_1 = (int)I_1.getX();
    switch(touchX){
       case tI_1:
          //do something            
       break;
 开发者_StackOverflow   }
    return false;
}


getX() and getY() are available only from API level 11 onwards. Try changing the API level of your application, might work.


you cant call getX() so directly like that... you should set an onTouchListener and a MotionEvent... try this Get the co-ordinates of a touch event on Android


If getX throws an Exception then use getLeft instead.

View source code (part):

// Added in API level 1
public final int getLeft() {
    return mLeft;
}

// Added in API level 11
public float getX() {
    return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜