我有imageView。我使用MotionEvent移动我的ImageView。如何为imageView设置缩放缩放功能。我没有使用任何GestureDetection功能。我需要用两根手指进行简单的捏合。
代码:
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v,MotionEvent event) {
// TODO Auto-generated method stub
layoutParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN :
{
parms = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
dx = event.getRawX() - parms.leftMargin;
dy = event.getRawY() - parms.topMargin;
}
break;
case MotionEvent.ACTION_MOVE :
{
x = event.getRawX();
y = event.getRawY();
parms.leftMargin = (int) (x-dx);
parms.topMargin = (int) (y - dy);
imageView.setLayoutParams(parms);
}
break;
case MotionEvent.ACTION_UP :
{
}
break;
}
return false;
}
});
}
});