{"id":4565,"date":"2021-09-01T13:39:13","date_gmt":"2021-09-01T05:39:13","guid":{"rendered":"http:\/\/122.152.205.50\/wordpress\/?p=4565"},"modified":"2021-09-01T13:39:13","modified_gmt":"2021-09-01T05:39:13","slug":"%e7%9b%b8%e5%af%b9%e5%b8%83%e5%b1%80","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=4565","title":{"rendered":"\u76f8\u5bf9\u5e03\u5c40"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4565\/#%E6%B5%8B%E9%87%8F%E8%BF%87%E7%A8%8B\" title=\"\u6d4b\u91cf\u8fc7\u7a0b\">\u6d4b\u91cf\u8fc7\u7a0b<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4565\/#%E7%AC%AC%E4%B8%80%E6%AD%A5%EF%BC%9A%E6%8E%92%E5%BA%8F\" title=\"\u7b2c\u4e00\u6b65\uff1a\u6392\u5e8f\">\u7b2c\u4e00\u6b65\uff1a\u6392\u5e8f<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4565\/#Pools\" title=\"Pools\">Pools<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4565\/#%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F\" title=\"\u62d3\u6251\u6392\u5e8f\">\u62d3\u6251\u6392\u5e8f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4565\/#%E6%8E%92%E5%BA%8F%E6%96%B9%E6%B3%95\" title=\"\u6392\u5e8f\u65b9\u6cd5\">\u6392\u5e8f\u65b9\u6cd5<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E9%87%8F%E8%BF%87%E7%A8%8B\"><\/span>\u6d4b\u91cf\u8fc7\u7a0b<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/87bc61b8a195\">https:\/\/www.jianshu.com\/p\/87bc61b8a195<\/a><br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/dnntjc\/article\/details\/82055393\">https:\/\/blog.csdn.net\/dnntjc\/article\/details\/82055393<\/a><br \/>\nonMeausre\u65b9\u6cd5\u89e3\u6790\uff08API28\uff09<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E7%AC%AC%E4%B8%80%E6%AD%A5%EF%BC%9A%E6%8E%92%E5%BA%8F\"><\/span>\u7b2c\u4e00\u6b65\uff1a\u6392\u5e8f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"line-numbers\"> @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        if (mDirtyHierarchy) {\n            mDirtyHierarchy = false;\n            sortChildren();\n        }\n...\n\n  @Override\n    public void requestLayout() {\n        super.requestLayout();\n        mDirtyHierarchy = true;\n    }\n<\/code><\/pre>\n<p>\u901a\u8fc7\u590d\u5199\u6253\u65e5\u5fd7\u53d1\u73b0requestLayout\u5148\u4e8eonMeasure\u6267\u884c\uff0c\u6240\u4ee5 mDirtyHierarchy\u662ftrue\uff0csortChildren\u65b9\u6cd5\u4f1a\u6267\u884c\u3002<br \/>\n\u641e\u6e05\u695a\u6392\u5e8f\uff0c\u9996\u5148\u5f97\u641e\u6e05\u695aRelativeLayout\u5185\u90e8\u7684\u6570\u636e\u7ed3\u6784\u7684\u67b6\u6784\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Pools\"><\/span>Pools<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/go_going\/article\/details\/81587289\">https:\/\/blog.csdn.net\/go_going\/article\/details\/81587289<\/a><br \/>\n\u4e3a\u4e86\u907f\u514d\u91cd\u590d\u7684\u521b\u5efa\u5bf9\u8c61\uff0c\u5927\u81f4\u601d\u60f3\u662f\uff1aPool\u7684acquire()\u65b9\u6cd5\u4f1a\u53d6\u7f13\u5b58\u6c60\u7684\u6700\u540e\u4e00\u4e2a\u5bf9\u8c61\u8fd4\u56de\u5e76\u5c06\u7f13\u5b58\u6c60\u8fd9\u4e2a\u4f4d\u7f6e\u7684\u5143\u7d20\u7f6e\u4e3anull\uff0crelease()\u65b9\u6cd5\u4f1a\u5c06\u5bf9\u8c61\u653e\u5230\u7f13\u5b58\u6c60\u3002\u8fd9\u6837\u53ea\u8981\u7f13\u5b58\u6c60\u6709\u5bf9\u8c61\uff0c\u5c31\u4e0d\u7528\u518dnew\u5bf9\u8c61\u4e86\u3002<\/p>\n<p>\u8fd9\u4e5f\u662f\u5185\u5b58\u4f18\u5316\u4e00\u79cd\u624b\u6bb5\uff0c\u9762\u8bd5\u53ef\u4ee5\u8bf4\u8bf4\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F\"><\/span>\u62d3\u6251\u6392\u5e8f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>\u6709\u5411\u56fe\u51fa\u5ea6\u4e0e\u5165\u5ea6\u7684\u6982\u5ff5<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/qq_43824791\/article\/details\/88792899\">https:\/\/blog.csdn.net\/qq_43824791\/article\/details\/88792899<\/a><br \/>\n\u5165\u5ea6\u5c31\u662f\uff1a\u6709\u5411\u56fe\u7684\u67d0\u4e2a\u9876\u70b9\u4f5c\u4e3a\u7ec8\u70b9\u7684\u6b21\u6570\u548c\u3002<br \/>\n\u51fa\u5ea6\u5c31\u662f\uff1a\u6709\u5411\u56fe\u7684\u67d0\u4e2a\u9876\u70b9\u4f5c\u4e3a\u8d77\u70b9\u7684\u6b21\u6570\u548c\u3002<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/qq_41713256\/article\/details\/80805338\">https:\/\/blog.csdn.net\/qq_41713256\/article\/details\/80805338<\/a> \uff08\u62d3\u6251\u6392\u5e8f\u5165\u95e8\uff09<\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/243da3f85032\">https:\/\/www.jianshu.com\/p\/243da3f85032<\/a>  \uff08\u7ed3\u5408RelativeLayout\u7684\u6e90\u7801\u8bf4\u660e\u62d3\u6251\u6392\u5e8f\u7684\u5e94\u7528\uff09<\/p>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%E6%8E%92%E5%BA%8F%E6%96%B9%E6%B3%95\"><\/span>\u6392\u5e8f\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"line-numbers\"> private void sortChildren() {\n        final int count = getChildCount();\n        if (mSortedVerticalChildren == null || mSortedVerticalChildren.length != count) {\n            mSortedVerticalChildren = new View[count];\n        }\n\n        if (mSortedHorizontalChildren == null || mSortedHorizontalChildren.length != count) {\n            mSortedHorizontalChildren = new View[count];\n        }\n\n        \/\/\u5c06\u5b50View\u88c5\u5165\u4e00\u4e2a\u4f9d\u8d56\u56fe\u4e2d\n        final DependencyGraph graph = mGraph;\n        graph.clear();\n\n        for (int i = 0; i &lt; count; i++) {\n            graph.add(getChildAt(i));\n        }\n\n        \/\/\u83b7\u53d6\u7ad6\u5411\u89c4\u5219\u76f8\u5173\u7684View\n        graph.getSortedViews(mSortedVerticalChildren, RULES_VERTICAL);\n\n        \/\/\u83b7\u53d6\u6c34\u5e73\u89c4\u5219\u76f8\u5173\u7684View\n        graph.getSortedViews(mSortedHorizontalChildren, RULES_HORIZONTAL);\n    }\n\n...\n\n       \/**\n         * Adds a view to the graph.\n         *\n         * @param view The view to be added as a node to the graph.\n         *\/\n        void add(View view) {\n            final int id = view.getId();\n            final Node node = Node.acquire(view);\n\n            if (id != View.NO_ID) {\n                mKeyNodes.put(id, node);\n            }\n\n            mNodes.add(node);\n        }\n<\/code><\/pre>\n<ul>\n<li>#### \u770b\u770b graph.getSortedViews\u7684\u5b9e\u73b0<br \/>\n\u8d8a\u662f\u5148\u88ab\u4f9d\u8d56\u7684View\uff0c\u8d8a\u5728\u6570\u7ec4\u7684\u524d\u9762\u3002<\/li>\n<\/ul>\n<pre><code class=\"line-numbers\"> \/**\n         * Builds a sorted list of views. The sorting order depends on the dependencies\n         * between the view. For instance, if view C needs view A to be processed first\n         * and view A needs view B to be processed first, the dependency graph\n         * is: B -&gt; A -&gt; C. The sorted array will contain views B, A and C in this order.\n         *\n         * @param sorted The sorted list of views. The length of this array must\n         *        be equal to getChildCount().\n         * @param rules The list of rules to take into account.\n         *\/\n        void getSortedViews(View[] sorted, int... rules) {\n            final ArrayDeque&lt;Node&gt; roots = findRoots(rules);\n            int index = 0;\n\n            Node node;\n            while ((node = roots.pollLast()) != null) {\n                final View view = node.view;\n                final int key = view.getId();\n\n                sorted[index++] = view;\n\n                final ArrayMap&lt;Node, DependencyGraph&gt; dependents = node.dependents;\n                final int count = dependents.size();\n                for (int i = 0; i &lt; count; i++) {\n                    final Node dependent = dependents.keyAt(i);\n                    final SparseArray&lt;Node&gt; dependencies = dependent.dependencies;\n\n                    dependencies.remove(key);\n                    if (dependencies.size() == 0) {\n                        roots.add(dependent);\n                    }\n                }\n            }\n\n            if (index &lt; sorted.length) {\n                throw new IllegalStateException(\"Circular dependencies cannot exist\"\n                        + \" in RelativeLayout\");\n            }\n        }\n<\/code><\/pre>\n<ul>\n<li>getSortedViews->findRoots:<br \/>\n\u6ce8\u610fdependency\u548cdependents\u7684\u8bcd\u6027\u7684\u5fae\u5999\u5dee\u522b\uff0cdependency\u662f\u52a8\u8bcd\u7684\u540d\u8bcd\uff0c\u8bf4\u660eroot node\u4e0d\u4f9d\u8d56\u5176\u5b83\u7684\u8282\u70b9\uff1b<br \/>\ndependents\u662f\u540d\u8bcd\uff0c\u9644\u5c5e\uff0c\u8bf4\u660e\u5b83\u53ef\u80fd\u88ab\u591a\u4e2a\u8282\u70b9\u6240\u4f9d\u8d56\u3002<br \/>\n\u5173\u4e8erules\u53ef\u4ee5\u53c2\u8003\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/87bc61b8a195\">https:\/\/www.jianshu.com\/p\/87bc61b8a195<\/a><\/li>\n<\/ul>\n<pre><code class=\"line-numbers\">  \/**\n         * Finds the roots of the graph. A root is a node with no dependency and\n         * with [0..n] dependents.\n         *\n         * @param rulesFilter The list of rules to consider when building the\n         *        dependencies\n         *\n         * @return A list of node, each being a root of the graph\n         *\/\n        private ArrayDeque&lt;Node&gt; findRoots(int[] rulesFilter) {\n            final SparseArray&lt;Node&gt; keyNodes = mKeyNodes;\n            final ArrayList&lt;Node&gt; nodes = mNodes;\n            final int count = nodes.size();\n\n            \/\/ Find roots can be invoked several times, so make sure to clear\n            \/\/ all dependents and dependencies before running the algorithm\n            for (int i = 0; i &lt; count; i++) {\n                final Node node = nodes.get(i);\n                node.dependents.clear();\n                node.dependencies.clear();\n            }\n\n            \/\/ Builds up the dependents and dependencies for each node of the graph\n            for (int i = 0; i &lt; count; i++) {\n                final Node node = nodes.get(i);\n\n                final LayoutParams layoutParams = (LayoutParams) node.view.getLayoutParams();\n                final int[] rules = layoutParams.mRules;\n                final int rulesCount = rulesFilter.length;\n\n                \/\/ Look only the the rules passed in parameter, this way we build only the\n                \/\/ dependencies for a specific set of rules\n                for (int j = 0; j &lt; rulesCount; j++) {\n                    final int rule = rules[rulesFilter[j]];\n                    if (rule &gt; 0) {\n                        \/\/ The node this node depends on\n                        final Node dependency = keyNodes.get(rule);\n                        \/\/ Skip unknowns and self dependencies\n                        if (dependency == null || dependency == node) {\n                            continue;\n                        }\n                        \/\/ Add the current node as a dependent\n                        dependency.dependents.put(node, this);\n                        \/\/ Add a dependency to the current node\n                        node.dependencies.put(rule, dependency);\n                    }\n                }\n            }\n\n            final ArrayDeque&lt;Node&gt; roots = mRoots;\n            roots.clear();\n\n            \/\/ Finds all the roots in the graph: all nodes with no dependencies\n            for (int i = 0; i &lt; count; i++) {\n                final Node node = nodes.get(i);\n                if (node.dependencies.size() == 0) roots.addLast(node);\n            }\n\n            return roots;\n        }\n<\/code><\/pre>\n<p>\u5176\u5b9e\u8fd9\u4e2a\u7b97\u6cd5\u8fd8\u662f\u633a\u7b80\u5355\u7684\uff0c\u5c31\u662f\u6839\u636erules\uff0c\u4f9d\u8d56\u4e0e\u88ab\u4f9d\u8d56\u7684\u5173\u7cfb\u6765\u786e\u5b9aroot nodes\u3002<br \/>\n\u6700\u7ec8\u8fd4\u56de\u7684\u5c31\u662f\u4e0d\u4f9d\u8d56\u4efb\u4f55\u5176\u5b83\u7684View\u7684\u7ed3\u70b9\u3002<br \/>\n ## \u7b2c\u4e8c\u6b65\uff1a\u6b63\u5f0f\u5f00\u59cb\u6d4b\u91cf<\/p>\n<button class=\"simplefavorite-button\" data-postid=\"4565\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u6d4b\u91cf\u8fc7\u7a0b\u7b2c\u4e00\u6b65\uff1a\u6392\u5e8fPools\u62d3\u6251\u6392\u5e8f\u6392\u5e8f\u65b9\u6cd5 \u6d4b\u91cf\u8fc7\u7a0b https:\/\/www.jiansh [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[197],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4565"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4565"}],"version-history":[{"count":1,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4565\/revisions"}],"predecessor-version":[{"id":4566,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4565\/revisions\/4566"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4565"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}