0

我已经成功地在 EditText 视图上实现了 onTouch 调整大小,但相同的代码似乎不适用于 ImageView。我的代码基本上是在视图的右下角获取 onTouch,然后相应地更改视图的布局参数。我不知道为什么相同的实现在 ImageView 上不起作用。请帮忙!!谢谢!!:)

protected View.OnTouchListener viewTouchListener=new View.OnTouchListener() {
       @Override
       public boolean onTouch(View view, MotionEvent event) {
           int x = (int) event.getX();
           int y = (int) event.getY();
           int width = view.getLayoutParams().width;
           int height = view.getLayoutParams().height;

               if (((x - width <= 20 && x - width > 0) || (width - x <= 20 && width - x > 0))&&(((y - height <= 20 && y - height > 0) || (height - y <= 20 && height - y > 0))) ){
                   switch (event.getAction()) {
                   case MotionEvent.ACTION_DOWN:
                       break;
                   case MotionEvent.ACTION_MOVE:
                       Log.e(">>", "width:" + width + " height:" + height + " x:" + x + " y:" + y);
                       view.getLayoutParams().width = x;
                       view.getLayoutParams().height = y;
                       view.requestLayout();
                       break;
                   case MotionEvent.ACTION_UP:
                       break;
               }
           }

将 onTouchListener 设置为 ImageView:

mImageView.setOnTouchListener(viewTouchListener);
4

0 回答 0