缩放 ViewGroup 中的 ImageView
我在 ViewGroup 中有不同的 ImageView 。每个 ImageView 都有这样的 onTouch 事件:
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
}
在 logcat 中,我看到 onTouch 事件已被处理,但没有任何反应。 在 ViewGroup 中,我使用 InterceptTouchEvent 来拖动 ImageView 并像 Android 主屏幕一样移动滑动视图。
我认为 ViewGroup 和 ImageView 在缩放触摸事件上存在问题,或者 ViewGroup 有特定设置。有人可以告诉我是否可以在 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论