Android的按钮的getX() [英] Android Button getX()

查看:111
本文介绍了Android的按钮的getX()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上的按钮调用的getX(),但日食告诉我有一个为按钮对象没有这样的方法。事实上,它在告诉我有没有的getX()进行查看或者,因为API说,有这令我感到困惑。
code:

 公共布尔onTouch(查看arg0中,MotionEvent ARG1){
    INT touchX =(int)的arg1.getX();
    INT敏感=(int)的arg1.getY();
    INT TI_1 =(int)的I_1.getX();
    开关(touchX){
       案例TI_1:
          //做一点事
       打破;
    }
    返回false;
}


解决方案

的getX()和的getY()只能从API级别11起。试着改变你的应用程序的API级别,可能会奏效。

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;
    }
    return false;
}

解决方案

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

这篇关于Android的按钮的getX()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆