我有我的Android 2.1应用程序,我有一个孩子的根布局,我可以点击,移动和缩放.一切都很好,只要根布局没有缩放.
我有这样的设置;
// Root, Moveable and zoomable
// Clickable, moveable and zoomable
// Clickable, moveable and zoomable
我喜欢缩放ZoomableRelativeLayout中的内容.我在ZoomableRelativeLayout类中缩放我的内容;
protected void dispatchDraw(Canvas canvas) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.scale(mScaleFactor, mScaleFactor, mXPointCenter, mYPointCenter);
super.dispatchDraw(canvas);
canvas.restore();
}
我得到了我想要的缩放结果,但问题是我想在缩放画布时点击Childviews到ZoomableRelativeLayout.
当比例为1(无缩放)时,与子视图的交互很好,但随着缩放我的缩放,就像触摸区域被翻译或其他东西一样,因为我不能再点击它们了.
我该如何解决?我试图在ZoomableRelativeLayout中覆盖onMeasure,就像这样;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension((int) (widthSize * mScaleFactor), (int) (heightSize * mScaleFactor));
}
如果有人可以帮助我!
好的,所以我改用了使用Matrix并使用画布比例来跟随;
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != View.GONE) {
child.layout((int) mPosX, (int) mPosY, (int) (mPosX + getWidth()), (int) (mPosY + getHeight()));
}
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension((int) (widthSize * mScaleFactor), (int) (heightSize * mScaleFactor));
}
我还有我的设置;
// Root, Moveable and zoomable
// Clickable, moveable and zoomable
// Clickable, moveable and zoomable
我可以移动布局,一切都很好,但是当我缩放时,作为ZoomableRelativeLayout的子项的RelativeLayouts不会被缩放..我该如何解决这个问题?我是否必须继承RelativeLayouts并覆盖onMeasure()或onLayout()或其他任何内容?