android W/View: requestLayout() improperly called by xxxView



2328     private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth,

2329             int desiredWindowHeight) {
2330         mLayoutRequested = false;
2331         mScrollMayChange = true;
2332         mInLayout = true;
2333 
2334         final View host = mView;
2335         if (DEBUG_ORIENTATION || DEBUG_LAYOUT) {
2336             Log.v(mTag, "Laying out " + host + " to (" +
2337                     host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")");
2338         }
2339 
2340         Trace.traceBegin(Trace.TRACE_TAG_VIEW, "layout");
2341         try {
2342             host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight());
2343 
2344             mInLayout = false;
2345             int numViewsRequestingLayout = mLayoutRequesters.size();
2346             if (numViewsRequestingLayout > 0) {
2347                 // requestLayout() was called during layout.
2348                 // If no layout-request flags are set on the requesting views, there is no problem.
2349                 // If some requests are still pending, then we need to clear those flags and do
2350                 // a full request/measure/layout pass to handle this situation.
2351                 ArrayList<View> validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters,
2352                         false);
2353                 if (validLayoutRequesters != null) {
2354                     // Set this flag to indicate that any further requests are happening during
2355                     // the second pass, which may result in posting those requests to the next
2356                     // frame instead
2357                     mHandlingLayoutInLayoutRequest = true;
2358 
2359                     // Process fresh layout requests, then measure and layout
2360                     int numValidRequests = validLayoutRequesters.size();
2361                     for (int i = 0; i < numValidRequests; ++i) {
2362                         final View view = validLayoutRequesters.get(i);
2363                         Log.w("View", "requestLayout() improperly called by " + view +
2364                                 " during layout: running second layout pass");
2365                         view.requestLayout();
2366                     }
2367                     measureHierarchy(host, lp, mView.getContext().getResources(),
2368                             desiredWindowWidth, desiredWindowHeight);
2369                     mInLayout = true; 
2370                     host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight());
2371 
2372                     mHandlingLayoutInLayoutRequest = false;
2373 
2374                     // Check the valid requests again, this time without checking/clearing the
2375                     // layout flags, since requests happening during the second pass get noop'd
2376                     validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, true);
2377                     if (validLayoutRequesters != null) {
2378                         final ArrayList<View> finalRequesters = validLayoutRequesters;
2379                         // Post second-pass requests to the next frame
2380                         getRunQueue().post(new Runnable() {
2381                             @Override
2382                             public void run() {
2383                                 int numValidRequests = finalRequesters.size();
2384                                 for (int i = 0; i < numValidRequests; ++i) {
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值