我已经在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);