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