android 布局缩放,android – 在RelativeLayout中缩放内容

我有我的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()或其他任何内容?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值