我有一个包含多个 ImageView 的 FrameLayout。在主要活动中,我记录了触摸事件,以便用手指(拖动)移动我的 FrameLayout 和里面的图像。
为此,我在 framelayout 的 onDraw 内调用 canvas.translate(x,y),该框架由活动触摸事件处理程序中的 invalidate() 调用。
一切都像一个魅力,除了翻译后,我无法点击我的 ImageView。其实每张图片的点击监听器还是在翻译前的原处。
我已经读过我应该在翻译后手动更新每个图像的布局,但是该怎么做呢?如果我用平移值更改边距,图像会进一步增加两倍......
我真的很感激任何帮助。
干杯。
这是我在 onDraw() 方法中翻译画布的 frameLayout(在我的主 Activity 中将 ImageView 添加到该 FrameLayout)。
public class TopView extends FrameLayout {
public float mPosX = 0;
public float mPosY = 0;
public TopView(Context context)
{
super(context);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(1920, 3200, Gravity.CENTER);
this.setLayoutParams(lp);
setWillNotDraw(false);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.translate(this.mPosX, this.mPosY);
}
}