0

I have successfully implemented onTouch resizing on EditText view, but the same code doesn't seem to be working on ImageView. My code is basically getting onTouch on bottom right corner of a view and then changing layout params of the view accordingly. I have no idea why the same implementation doesn't work on ImageView. Please help!! Thanks!! :)

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

Setting onTouchListener to the ImageView:

mImageView.setOnTouchListener(viewTouchListener);
Alex
  • 881
  • 2
  • 10
  • 24
  • You have to get the `LayoutParams` object reference, change it, then call `setLayoutParams()` with that object reference. – DeeV Apr 19 '15 at 14:12
  • i reckon requestLayout() works the same as setLayoutParams()? I have tried changing to setLayoutParams() too but it just doesn't work @DeeV – Alex Apr 19 '15 at 14:45
  • `setlayoutParams()` actually calls `requestLayout()` internally, but it does other things too. – DeeV Apr 19 '15 at 15:25
  • Also have you verified your move action is even being executed? – DeeV Apr 19 '15 at 15:29
  • The log doesn't show up when I touch the bottom right corner of the image view, I guess it is not being executed, but when I apply it on my edit text, it is being executed. No idea why it is not working on my ImageView. @DeeV – Alex Apr 19 '15 at 15:33

0 Answers0