【问题标题】:How to make bitmap invisible ontouch in android? [closed]如何在android中使位图不可见? [关闭]
【发布时间】:2012-08-09 23:32:14
【问题描述】:

我在画布上绘制了一个位图,我想设置一个 ontouch 监听器,所以 一旦用户触摸位图,它就会变得不可见。

【问题讨论】:

  • 发布代码。发布有关您尝试过的内容的详细信息?
  • 查看您自己的问题答案here
  • 嘿,在你们都做 -4 和迈克盖茨之前读过,你们疯了,你们不知道位图和网格视图之间的区别吗?

标签: android android-layout android-widget


【解决方案1】:

这样做:

    @Override
    public boolean onTouch(final View view, MotionEvent event) {

              final int action = event.getAction();

                     int x = event.getX()  // or getRawX();
                     int y = event.getY();

                    switch(action){
                          case MotionEvent.ACTION_DOWN:

                   if (x >= xOfYourBitmap && x < (xOfYourBitmap +yourBitmap.getWidth())
                       && y >= yOfYourBitmap && y < (yOfYourBitmap + yourBitmap.getHeight())) {
        //You've pressed on your bitmap
    }
    break;
}
     }

【讨论】:

  • 什么是 idofbitmap 我们如何获得它?
猜你喜欢
  • 2018-11-09
  • 1970-01-01
  • 1970-01-01
  • 2013-12-02
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 2014-06-19
  • 1970-01-01
相关资源
最近更新 更多