Zooming a ImageView in a ViewGroup
I have different ImageView in a ViewGroup. Every ImageView has onTouch event like this:
public boolean onTouch(View v,MotionEvent event){
ImageView view = (ImageView)v;
// Dump touch event to log
dumpEvent(event);
// Handle touch events here...
switch (event.getAction() & MotionEvent.ACTION_MASK )
{
case MotionEvent.ACTION_DOWN:
savedMatrix.set(matrix);
start.set(event.getX(), event.getY());
Log.d(TAG, "mode=DRAG");
mode = DRAG;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
mode = NONE;
Log.d(TAG, "mode=NONE");
break;
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = spacing(event);
Log.d(TAG, "oldDist=" + oldDist);
if (oldDist > 10f)
{
savedMatrix.set(matrix);
midPoint(mid, event);
mode = ZOOM;
Log.d(TAG, "mode=ZOOM");
}
break;
case MotionEvent.ACTION_MOVE:
if (mode == DRAG)
{
matrix.set(savedMatrix);
matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
}
else if (mode == ZOOM)
{
float newDist = spacing(event);
Log.d(TAG, "newDist=" + newDist);
if (newDist > 10f)
{
matrix.set(savedMatrix);
float scale = newDist / oldDist;
matrix.postScale(scale,开发者_运维技巧 scale, mid.x, mid.y);
}
}
break;
}
Log.d(TAG, "setting matrix " + matrix);
view.setImageMatrix(matrix);
return true; // Indicate event was handled
}
In logcat I see that onTouch event was handled but nothing happen. In ViewGroup I use InterceptTouchEvent for drag ImageView and move sliding view like android homescreen.
I think that there's a problem between ViewGroup and ImageView on dispacth touch event for zoom or there's a particular setting for ViewGroup. Can someone tell me if is possible zoom inside a child of a ViewGroup and how implement it?
精彩评论