android 强制重新布局,android – 强制重新布局视图组,包括其所有子项

我正在编写一个可以放大的自定义布局(扩展FrameLayout).它的所有子节点也是自定义视图,它实际上通过getter方法从父节点获取比例因子,并通过设置缩放尺寸来相应缩放

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

float scaleFactor = ((CustomLayout) getParent()).getCurrentScale();

setMeasuredDimension((int) (getMeasuredWidth() * scaleFactor), (int) (getMeasuredHeight() * scaleFactor));

}

我正在使用ScaleGestureDetector来检测“缩放到缩放”手势并更改布局的scaleFactor.然后我通过调用requestLayout强制自定义布局上的布局.不幸的是,这似乎对其孩子没有任何影响.孩子们的onMeasure& onLayout永远不会被调用,即使父母经历了它的措施&布局周期.但是,如果我直接在其中一个孩子上调用requestLayout,那么只要该孩子根据父母中设置的比例因子进行缩放!

似乎除非在视图上专门调用requestLayout,否则它实际上不会再次测量自身,而是使用某种缓存.从视图的源代码中可以看出这一点

if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == null) {

// Only trigger request-during-layout logic if this is the view requesting it,

// not the views in its parent hierarchy

ViewRootImpl viewRoot = getViewRootImpl();

if (viewRoot != null && viewRoot.isInLayout()) {

if (!viewRoot.requestLayoutDuringLayout(this)) {

return;

}

}

mAttachInfo.mViewRequestingLayout = this;

}

我如何强迫孩子们在他们的父母上调用requestLayout时再次测量自己?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值