{"id":3971,"date":"2021-02-05T16:42:13","date_gmt":"2021-02-05T08:42:13","guid":{"rendered":"http:\/\/122.152.205.50\/wordpress\/?p=3971"},"modified":"2021-08-31T13:59:06","modified_gmt":"2021-08-31T05:59:06","slug":"view%e4%bd%93%e7%b3%bb%ef%bc%88%e5%9b%9b%ef%bc%89%ef%bc%9aview%e7%9a%84%e7%bb%98%e5%88%b6%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971","title":{"rendered":"View\u4f53\u7cfb\uff08\u56db\uff09\uff1aView\u7684\u7ed8\u5236\u539f\u7406"},"content":{"rendered":"<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/5baa20d3d953\">https:\/\/www.jianshu.com\/p\/5baa20d3d953<\/a><br \/>\n\uff08\u6211\u5728\u7b80\u4e66\u4e0a\u7684\u6587\u7ae0\uff09<\/p>\n<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=3971\/#%E5%9C%BA%E6%99%AF1\" title=\"\u573a\u666f1\">\u573a\u666f1<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E5%9C%BA%E6%99%AF2\" title=\"\u573a\u666f2\">\u573a\u666f2<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#https_wwwjianshucompca118d704b5e\" title=\"https:\/\/www.jianshu.com\/p\/ca118d704b5e\">https:\/\/www.jianshu.com\/p\/ca118d704b5e<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E8%87%AA%E5%AE%9A%E4%B9%89View%E6%A0%B8%E5%BF%83\" title=\"\u81ea\u5b9a\u4e49View\u6838\u5fc3\">\u81ea\u5b9a\u4e49View\u6838\u5fc3<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E6%A0%B8%E5%BF%83%E4%B8%80%EF%BC%9AMeasure%E6%B5%8B%E9%87%8F\" title=\"\u6838\u5fc3\u4e00\uff1aMeasure(\u6d4b\u91cf)\">\u6838\u5fc3\u4e00\uff1aMeasure(\u6d4b\u91cf)<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E6%B5%8B%E9%87%8F%E6%B5%81%E7%A8%8B%E6%95%B4%E7%90%86\" title=\"\u6d4b\u91cf\u6d41\u7a0b\u6574\u7406\">\u6d4b\u91cf\u6d41\u7a0b\u6574\u7406<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E8%A1%A5%E5%85%85\" title=\"\u8865\u5145\">\u8865\u5145<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E6%A0%B8%E5%BF%83%E4%BA%8C%EF%BC%9ALayout%E5%B8%83%E5%B1%80\" title=\"\u6838\u5fc3\u4e8c\uff1aLayout(\u5e03\u5c40)\">\u6838\u5fc3\u4e8c\uff1aLayout(\u5e03\u5c40)<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E8%A1%A5%E5%85%85-2\" title=\"\u8865\u5145\">\u8865\u5145<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E6%A0%B8%E5%BF%83%E4%B8%89%EF%BC%9ADraw%E7%BB%98%E5%88%B6\" title=\"\u6838\u5fc3\u4e09\uff1aDraw(\u7ed8\u5236)\">\u6838\u5fc3\u4e09\uff1aDraw(\u7ed8\u5236)<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E5%BE%AA%E7%8E%AF%E7%BB%98%E5%88%B6%E6%9C%BA%E5%88%B6\" title=\"\u5faa\u73af\u7ed8\u5236\u673a\u5236\">\u5faa\u73af\u7ed8\u5236\u673a\u5236<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#View%E7%9A%84%E7%BB%98%E5%88%B6%E4%B8%8D%E4%BB%85%E4%BB%85%E6%98%AFonDraw%E6%96%B9%E6%B3%95\" title=\"View\u7684\u7ed8\u5236\u4e0d\u4ec5\u4ec5\u662fonDraw\u65b9\u6cd5\">View\u7684\u7ed8\u5236\u4e0d\u4ec5\u4ec5\u662fonDraw\u65b9\u6cd5<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-13\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E8%87%AA%E5%AE%9A%E4%B9%89View%E5%AE%9E%E8%B7%B5\" title=\"\u81ea\u5b9a\u4e49View\u5b9e\u8df5\">\u81ea\u5b9a\u4e49View\u5b9e\u8df5<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-14\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E7%BB%98%E5%88%B6%E5%86%B2%E7%AA%81\" title=\"\u7ed8\u5236\u51b2\u7a81\">\u7ed8\u5236\u51b2\u7a81<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-15\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#1ScrollView%E4%B8%8EListView%E5%B5%8C%E5%A5%97%E5%86%B2%E7%AA%81%E7%9A%84%E9%97%AE%E9%A2%98\" title=\"1.ScrollView\u4e0eListView\u5d4c\u5957\u51b2\u7a81\u7684\u95ee\u9898\">1.ScrollView\u4e0eListView\u5d4c\u5957\u51b2\u7a81\u7684\u95ee\u9898<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-16\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E5%85%88%E6%84%9F%E6%80%A7%E5%9C%B0%E5%86%99%E4%B8%80%E4%BA%9BDemo\" title=\"\u5148\u611f\u6027\u5730\u5199\u4e00\u4e9bDemo\">\u5148\u611f\u6027\u5730\u5199\u4e00\u4e9bDemo<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-17\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E6%89%BE%E5%88%B0%E7%AA%81%E7%A0%B4%E5%8F%A3%E5%88%86%E6%9E%90\" title=\"\u627e\u5230\u7a81\u7834\u53e3\u5206\u6790\">\u627e\u5230\u7a81\u7834\u53e3\u5206\u6790<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-18\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E6%80%BB%E7%BB%93%EF%BC%9A\" title=\"\u603b\u7ed3\uff1a\">\u603b\u7ed3\uff1a<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-19\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#ScrollView%E5%B5%8C%E5%A5%97RelativeLayout%E5%86%B2%E7%AA%81%E7%A4%BA%E4%BE%8B1%EF%BC%9A\" title=\"ScrollView\u5d4c\u5957RelativeLayout\u51b2\u7a81\u793a\u4f8b1\uff1a\">ScrollView\u5d4c\u5957RelativeLayout\u51b2\u7a81\u793a\u4f8b1\uff1a<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-20\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E7%8E%B0%E8%B1%A1\" title=\"\u73b0\u8c61\">\u73b0\u8c61<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-21\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E5%88%86%E6%9E%90RelativeLayout%E7%9A%84%E6%B5%8B%E9%87%8F%E6%96%B9%E6%B3%95%EF%BC%88%E6%B2%A1%E6%9C%89%E5%AD%90View%E7%9A%84%E6%83%85%E5%86%B5%EF%BC%89\" title=\"\u5206\u6790RelativeLayout\u7684\u6d4b\u91cf\u65b9\u6cd5\uff08\u6ca1\u6709\u5b50View\u7684\u60c5\u51b5\uff09\">\u5206\u6790RelativeLayout\u7684\u6d4b\u91cf\u65b9\u6cd5\uff08\u6ca1\u6709\u5b50View\u7684\u60c5\u51b5\uff09<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-22\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#ScrollView%E5%B5%8C%E5%A5%97RelativeLayout%E5%86%B2%E7%AA%81%E7%A4%BA%E4%BE%8B2%EF%BC%9A\" title=\"ScrollView\u5d4c\u5957RelativeLayout\u51b2\u7a81\u793a\u4f8b2\uff1a\">ScrollView\u5d4c\u5957RelativeLayout\u51b2\u7a81\u793a\u4f8b2\uff1a<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-23\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#%E5%88%86%E6%9E%90RelativeLayout%E7%9A%84%E6%B5%8B%E9%87%8F%E6%96%B9%E6%B3%95%EF%BC%88%E6%9C%89%E5%AD%90View%E7%9A%84%E6%83%85%E5%86%B5%EF%BC%89\" title=\"\u5206\u6790RelativeLayout\u7684\u6d4b\u91cf\u65b9\u6cd5\uff08\u6709\u5b50View\u7684\u60c5\u51b5\uff09\">\u5206\u6790RelativeLayout\u7684\u6d4b\u91cf\u65b9\u6cd5\uff08\u6709\u5b50View\u7684\u60c5\u51b5\uff09<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-24\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=3971\/#ScrollView%E5%B5%8C%E5%A5%97View%E5%86%B2%E7%AA%81%E7%A4%BA%E4%BE%8B%EF%BC%9A\" title=\"ScrollView\u5d4c\u5957View\u51b2\u7a81\u793a\u4f8b\uff1a\">ScrollView\u5d4c\u5957View\u51b2\u7a81\u793a\u4f8b\uff1a<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E5%9C%BA%E6%99%AF1\"><\/span>\u573a\u666f1<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u5f80Fragment\u91cc\u52a8\u6001\u6dfb\u52a0\u4e00\u4e2a\u81ea\u5b9a\u4e49View<\/p>\n<pre><code class=\"language-java line-numbers\">  final ToastView toastView = new ToastView(webViewFragment.getContext());\n                    webViewFragment.getContentView().addView(toastView);\n                    webViewFragmentController = new WebViewFragmentController(webViewFragment, toastView);\n                    toastView.init(webViewFragment,toastParamsBean);\n<\/code><\/pre>\n<p>\u5e03\u5c40\u5982\u4e0b<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-95d62af6a5d792e6.jpg\" alt=\"\" \/><br \/>\n\u9700\u6c42\u5c31\u662f\u5f53\u53ea\u663e\u793atv_title\u65f6\uff0crl_wrapper\u7684\u5bbd\u9ad8\u4e3awrapper\uff0c\u4f46\u662f\u65e0\u8bba\u600e\u4e48\u6d4b\u91cf\u5565\u7684\u65b9\u6cd5\u90fd\u8bd5\u8fc7\u4e86\u4e0d\u884c\u3002<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-8d8ff447fe2565f3.png\" alt=\"\" \/><br \/>\n\u6700\u7ec8\u81ea\u5df1\u8bd5\u51fa\u53ef\u884c\u7684\u4ee3\u7801\uff0c\u4f46\u662f\u5e76\u4e0d\u6e05\u695a\u4ec0\u4e48\u4e2a\u539f\u7406<\/p>\n<pre><code class=\"language-java line-numbers\"> \/**\n     * \u6d4b\u91cfView\u8bbe\u7f6e\u5177\u4f53\u5927\u5c0f(\u6ce8\u610f\u4e00\u4e8c\u4e09\u6b65\uff0c\u4e00\u6b65\u4e5f\u4e0d\u80fd\u5c11\u3002)\n     * @param view\n     *\/\n    public static void measureViewWrapWrap(View view){\n        \/\/\u7b2c\u4e00\u6b65\n        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();\n        layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;\n        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;\n        view.setLayoutParams(layoutParams);\n\n        \/\/\u7b2c\u4e8c\u6b65\n        int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);\n        int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);\n        Logger.d(TAG, \"measureView: \" +  \"w = \" + w + \",h = \" + h);\n        view.measure(w, h);\n\n        \/\/\u7b2c\u4e09\u6b65\n        int mWidth = view.getMeasuredWidth();\n        int mHeight = view.getMeasuredHeight();\n        Logger.e(TAG, \"measureViewWrapWrap: mWidth = \" + mWidth + \",mHeight = \" + mHeight);\n\n        ViewGroup.LayoutParams layoutParams2 = view.getLayoutParams();\n        layoutParams2.width = mWidth;\n        layoutParams2.height = mHeight;\n        view.setLayoutParams(layoutParams2);\n    }\n<\/code><\/pre>\n<h1><span class=\"ez-toc-section\" id=\"%E5%9C%BA%E6%99%AF2\"><\/span>\u573a\u666f2<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>wrap\u6307\u5b9a\u65e0\u6548<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/u010648159\/article\/details\/81112643\">https:\/\/blog.csdn.net\/u010648159\/article\/details\/81112643<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"https_wwwjianshucompca118d704b5e\"><\/span><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/ca118d704b5e\">https:\/\/www.jianshu.com\/p\/ca118d704b5e<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u73b0\u5982\u4eca\uff0c\u4f5c\u4e3a\u4e00\u4e2a5\u5e74\u7a0b\u5e8f\u733f\uff0c\u4e0d\u80fd\u518d\u5f97\u8fc7\u4e14\u8fc7\uff0c\u61f5\u61f5\u61c2\u61c2\u5730\u5199\u4ee3\u7801\u4e86\u3002\u51c6\u5907\u4ee5\u8fd9\u4e2a\u95ee\u9898\u4e3a\u5bfc\u5411\uff0c\u6df1\u5165\u7814\u7a76\u4e00\u4e0bAndroid\u52a8\u6001\u5e03\u5c40\u76f8\u5173\u7684\u77e5\u8bc6\u3002<br \/>\n\u5728<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/jiangxuqaz\/article\/details\/46941479\">https:\/\/blog.csdn.net\/jiangxuqaz\/article\/details\/46941479<\/a><br \/>\n\u5b83\u91cc\u9762\u6709\u53e5\u8bdd\uff1a\"\u5b50View\u7684widthMeasureSpec\u548cheightMeasureSpec\u662f\u7531\u7236View\u7684widthMeasureSpec\u548cheightMeasureSpec\uff0cLayoutParams\u548c\u5b50ViewMarginLayoutParams\u51b3\u5b9a\u7684\"<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/08047f7f8fcf\">https:\/\/www.jianshu.com\/p\/08047f7f8fcf<\/a><br \/>\n\u8fd92\u7bc7\u6587\u7ae0\u91cc\u6211\u597d\u50cf\u627e\u5230\u4e86\u7b54\u6848\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E8%87%AA%E5%AE%9A%E4%B9%89View%E6%A0%B8%E5%BF%83\"><\/span>\u81ea\u5b9a\u4e49View\u6838\u5fc3<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"%E6%A0%B8%E5%BF%83%E4%B8%80%EF%BC%9AMeasure%E6%B5%8B%E9%87%8F\"><\/span>\u6838\u5fc3\u4e00\uff1aMeasure(\u6d4b\u91cf)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>1.<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/08047f7f8fcf\">https:\/\/www.jianshu.com\/p\/08047f7f8fcf<\/a> \uff08\u8bf4\u7684\u53ef\u80fd\u6709\u70b9\u7f9e\u6da9\u96be\u61c2\uff0c\u8c8c\u4f3c\u662f\u4e00\u79cd\u54f2\u7406\u63d0\u70bc\uff0c\u4f46\u662f\u6700\u8be6\u7ec6\u3002\u6700\u540e\u7684\u793a\u4f8b\uff0c\u4e5f\u6ca1\u6709\u7ed9\u51fa\u5b8c\u6574\u4ee3\u7801\uff0c\u53ea\u80fd\u4ed6\u81ea\u5df1\u77e5\u9053\u600e\u4e48\u56de\u4e8b\u3002\uff09<br \/>\n\u4f5c\u8005\u4e00\u76f4\u5f3a\u8c03\u7684\u91cd\u70b9<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-c6741fbf37ca3f74.png\" alt=\"\" \/><br \/>\n\uff0c\"\u9700\u6c42\"\u4e00\u8bcd\uff0c\u5e76\u4e0d\u662f\u4f5c\u8005\u72ec\u521b\uff0c\u5176\u5b9e\u5b98\u65b9\u7c7b\u7684\u8bf4\u660e\u5c31\u662f\u8fd9\u4e48\u5199\u7684\u3002<br \/>\n\u53e6\u5916\u4e00\u4e2a\u91cd\u70b9\uff1aLayoutParams\uff0c\u5b50View\u7684Measure\u5e76\u4e0d\u662f\u72ec\u7acb\u7684\uff0c\u800c\u662f\u548c\u7236View\u662f\u606f\u606f\u76f8\u5173\u7684\uff0c\u901a\u8fc7LayoutParams\u5411\u7236\u7c7b\u8868\u8fbe\u81ea\u5df1\u7684\u671f\u671b\uff0c\u7236\u7c7b\u624d\u77e5\u9053Measure\u5b50View\u4f20\u9012\u4ec0\u4e48\u9700\u6c42\u3002<\/p>\n<p>2.<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/a553181867\/article\/details\/51494058\">https:\/\/blog.csdn.net\/a553181867\/article\/details\/51494058<\/a><br \/>\n\u8fd9\u7bc7\u5206\u6790\u6e90\u7801\uff0c\u5341\u5206\u5230\u4f4d\uff0c\u601d\u8def\u7279\u522b\u5730\u6e05\u6670\uff0c\u5efa\u8bae\u591a\u770b\u51e0\u904d\u3002<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-73efa63c667370d0.png\" alt=\"\" \/><br \/>\n\u4e0a\u9762\u8fd9\u53e5\u8bdd\u4e5f\u6b63\u597d\u89e3\u51b3\u4e86\u6211\u535a\u5ba2\u6700\u5f00\u59cb\u63d0\u51fa\u7684\u7591\u95ee\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E9%87%8F%E6%B5%81%E7%A8%8B%E6%95%B4%E7%90%86\"><\/span>\u6d4b\u91cf\u6d41\u7a0b\u6574\u7406<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u4ece\u9876\u7ea7View\u5f00\u59cb\u4e86\u6d4b\u91cf\u6d41\u7a0b\uff0c\u7136\u540e\u7531\u5916\u5230\u5185\uff0c\u9010\u7ea7\u6d4b\u91cf\uff0c\u8c03\u7528View#measure\u65b9\u6cd5(final\u4fee\u9970\uff0c\u4e0d\u53ef\u66f4\u6539)\uff0cmeasure\u65b9\u6cd5\u8c03\u7528onMeasure\u65b9\u6cd5(\u53ef\u4ee5\u88ab\u590d\u5199\uff0c\u4e0d\u540c\u7684View\u7684\u5b9e\u73b0\u57fa\u672c\u4e0d\u4e00\u6837 )<\/p>\n<ul>\n<li>View\u7684onMeasure\u65b9\u6cd5<\/li>\n<\/ul>\n<pre><code class=\"language-java line-numbers\">    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),\n                getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));\n    }\n<\/code><\/pre>\n<p>\u4ec5\u4ec5\u662f\u4fdd\u5b58\u4e86\u6d4b\u91cf\u7684\u5bbd\u9ad8<\/p>\n<ul>\n<li>ViewGroup\u7684onMeasure\u65b9\u6cd5<br \/>\n\u548cView\u4e00\u6837\uff0c\u672a\u505a\u590d\u5199\u3002<\/p>\n<\/li>\n<li>\n<p>\u5176\u5b83View\u7684onMeasure\u65b9\u6cd5<br \/>\n\u57fa\u672c\u90fd\u4f1a\u590d\u5199\uff0c\u57fa\u672c\u90fd\u4f1a\u7ed3\u5408\u81ea\u5df1\u672c\u8eab\u7684\u5bbd\u9ad8\u3001\u81ea\u5df1\u672c\u8eab\u7684\u5e03\u5c40\u53c2\u6570\u3001\u5b50View\u7684LayoutParams\u53bb\u7efc\u5408\u8ba1\u7b97\u51fa\u5b50View\u7684\u5bbd\u548c\u9ad8\u7684MeasureSpec\uff0c\u7136\u540e\u8c03\u7528View#measure\u65b9\u6cd5\u5bf9\u5b50View\u8fdb\u884c\u6d4b\u91cf\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u4ee3\u7801\u4e0a\u8868\u73b0\u4e3a<\/strong>\uff1a<br \/>\n\u90fd\u6709measureChild[XXX]\u65b9\u6cd5\uff08\u81ea\u5df1\u5b9a\u4e49\u7684\u6216\u8005\u590d\u7528ViewGroup\u7684\uff0cFrameLayout\u5c31\u662f\u590d\u7528ViewGroup\u7684\uff0cRelativeLayout\u5c31\u662f\u81ea\u5b9a\u4e49\u7684\u65b9\u6cd5\uff0c<strong>measureChild[XXX]\u65b9\u6cd5\u5b50\u7c7b\u53ef\u80fd\u4f1a\u590d\u5199<\/strong>\uff09\uff0c\u7136\u540e\u5728\u8fd9\u4e2a\u65b9\u6cd5\u5185\u8c03\u7528getChildMeasureSpec\u65b9\u6cd5\uff08\u81ea\u5df1\u5b9a\u4e49\u7684\u6216\u8005\u590d\u7528ViewGroup\u7684\uff09\u8ba1\u7b97\u51fa\u5b50View\u7684\u5bbd\u548c\u9ad8\u7684MeasureSpec\u503c\u3002<\/p>\n<p><strong>\u5b50View\u7684\u5e03\u5c40\u53c2\u6570\u548c\u6d4b\u91cf\u5927\u5c0f\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5f53\u524dView\u91cd\u65b0\u6d4b\u91cf<\/strong>\uff0c\u5982FrameLayout\uff0c\u770bmeasureMatchParentChildren\u8fd9\u4e2a\u53d8\u91cf\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E8%A1%A5%E5%85%85\"><\/span>\u8865\u5145<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u4f46\u662f\uff0c\u5173\u4e8e\u535a\u5ba2\u6211\u6709\u51e0\u70b9\u9700\u8981\u8865\u5145\u3002<br \/>\n- 1.\u5bf9\u4e8eDecorView\u6765\u8bf4\uff0c\u5b83\u5df2\u7ecf\u662f\u9876\u5c42view\u4e86\uff0c\u6ca1\u6709\u7236\u5bb9\u5668\uff0c\u90a3\u4e48\u5b83\u7684MeasureSpec\u600e\u4e48\u6765\u7684\u5462<br \/>\n\u5173\u4e8egetRootMeasureSpec\u8fd9\u4e2a\u65b9\u6cd5\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0c\u4e00\u76f4\u8ffd\u6eaf\uff1alp ----> mWindowAttributes ----> WindowManager.LayoutParams<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-8f461e3bf33a1da2.png\" alt=\"\" \/><br \/>\n\u6240\u4ee5\u7531\u6b64\u65ad\u5b9a\uff1aDecorView\u7684MeasureSpec\u7684mode\u662fEXACTLY,size\u5c31\u662f\u7a97\u53e3\u7684\u5bbd\u9ad8\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E6%A0%B8%E5%BF%83%E4%BA%8C%EF%BC%9ALayout%E5%B8%83%E5%B1%80\"><\/span>\u6838\u5fc3\u4e8c\uff1aLayout(\u5e03\u5c40)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8fd8\u662f\u7ed3\u5408\u4e0a\u9762\u8fd9\u4f4d\u5927\u795e\u7684\u535a\u5ba2\u5206\u6790<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/a553181867\/article\/details\/51524527\">https:\/\/blog.csdn.net\/a553181867\/article\/details\/51524527<\/a><br \/>\n\u548cmeasure\u7684\u5f62\u5f0f\u5dee\u4e0d\u591a\uff0c\u5b50View\u4e5f\u662f\u901a\u8fc7\u590d\u5199onLayout\u8fbe\u5230\u4e0d\u540c\u7684\u6548\u679c\u3002<br \/>\n- View\u7684onLayout\u65b9\u6cd5<br \/>\n\u7a7a\u5b9e\u73b0\uff0c\u56e0\u4e3aView\u4e0d\u9700\u8981\u5e03\u5c40\u5176\u5b83\u7684View\u3002<br \/>\n- ViewGroup\u7684onLayout\u65b9\u6cd5<br \/>\n\u62bd\u8c61\u65b9\u6cd5\uff0c\u8fd9\u91cc\u6709java\u8bed\u6cd5\u6709\u70b9\u7279\u6b8a\uff1aView\u7684onLayout\u662f\u7a7a\u5b9e\u73b0\uff0c\u5b83\u7684\u5b50\u7c7bViewGroup\u53ef\u4ee5\u628a\u5b83\u590d\u5199\u6210\u62bd\u8c61\u65b9\u6cd5\uff0c\u800c\u4e14\u65b9\u6cd5\u57df\u7531protected\u53d8\u4e3apublic\u3002<br \/>\n\u6b63\u56e0\u4e3aViewGroup\u6ca1\u6709\u590d\u5199onLayout\u65b9\u6cd5\uff0c\u6240\u4ee5xml\u76f4\u63a5\u7528ViewGroup\u5d4c\u5957View\uff0cView\u662f\u4e0d\u4f1a\u663e\u793a\u7684\u3002<\/p>\n<ul>\n<li>\u5176\u5b83View\u7684onLayout\u65b9\u6cd5<br \/>\n\u6839\u636e\u5b50View\u7684\u5404\u79cd\u53ef\u80fd\u5e72\u6270\u5e03\u5c40\u4f4d\u7f6e\u7684\u53c2\u6570\uff0c\u5b50View\u7684\u6d4b\u91cf\u8fc7\u7684\u5bbd\u9ad8\uff0c\u8c03\u7528\u5b50View\u7684layout\u65b9\u6cd5\u8fdb\u884c\u5e03\u5c40\u3002<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%E8%A1%A5%E5%85%85-2\"><\/span>\u8865\u5145<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>1.\u7ea0\u6b63\u4e00\u4e0b\u535a\u5ba2\u7684\u4e00\u4e2a\u9519\u8bef<br \/>\nView\u7684layout\u5e76\u975e\u662ffinal\u7684\uff0c\u800c\u662fDecorView\u6ca1\u6709\u590d\u5199\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E6%A0%B8%E5%BF%83%E4%B8%89%EF%BC%9ADraw%E7%BB%98%E5%88%B6\"><\/span>\u6838\u5fc3\u4e09\uff1aDraw(\u7ed8\u5236)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8fd8\u662f\u7ed3\u5408\u4e0a\u9762\u8fd9\u4f4d\u5927\u795e\u7684\u535a\u5ba2\u5206\u6790<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/a553181867\/article\/details\/51570854\">https:\/\/blog.csdn.net\/a553181867\/article\/details\/51570854<\/a><br \/>\n\u53ef\u4ee5\u770b\u51fa\uff0cView\u7684Draw\u6d41\u7a0b\u4e5f\u6bd4\u8f83\u590d\u6742\u7684\u3002performDraw() ---> draw(boolean fullRedrawNeeded) ---> drawSoftware --->  mView.draw(canvas)<br \/>\n\u548cmeasure\u3001layout\u7684\u5f62\u5f0f\u5dee\u4e0d\u591a\uff0c\u5b50View\u4e5f\u662f\u901a\u8fc7\u590d\u5199onDraw\u8fbe\u5230\u4e0d\u540c\u7684\u6548\u679c\u3002<strong>\u5982\u679cView\u662f\u900f\u660e\u7684\uff0c\u5c31\u6ca1\u6709\u8c03\u7528onDraw\uff0c\u56e0\u4e3a\u900f\u660e\u7684View\u6ca1\u6709\u7ed8\u5236\u7684\u610f\u4e49<\/strong>\u3002<\/p>\n<ul>\n<li>View\u7684onDraw\u65b9\u6cd5<br \/>\n\u7a7a\u5b9e\u73b0<\/li>\n<li>ViewGroup\u7684onDraw\u65b9\u6cd5<br \/>\n\u548cView\u4e00\u6837\uff0c\u672a\u590d\u5199\u3002<\/li>\n<li>\u5176\u5b83View\u7684onDraw\u65b9\u6cd5<br \/>\n\u4e00\u822c\u90fd\u672a\u590d\u5199<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%E5%BE%AA%E7%8E%AF%E7%BB%98%E5%88%B6%E6%9C%BA%E5%88%B6\"><\/span>\u5faa\u73af\u7ed8\u5236\u673a\u5236<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u548cmeasure\u3001layout\u4e0d\u540c\uff0cdraw\u7684\u5faa\u73af\u9012\u5f52\u4e0d\u662f\u5728onXXX\u65b9\u6cd5\u91cc\u5b9e\u73b0\u3002<br \/>\nView\u7684draw\u65b9\u6cd5\u91cc\u4f1a\u8c03\u7528dispatchDraw(Canvas canvas)\u65b9\u6cd5\uff0cView\u672c\u8eab\u8fd9\u4e2a\u65b9\u6cd5\u662f\u7a7a\u5b9e\u73b0\uff0c\u4f46\u662fViewGroup\u4f5c\u4e86\u5b9e\u73b0\uff0c\u4f1a\u8c03\u7528drawChild\u65b9\u6cd5\uff0c\u6b64\u65b9\u6cd5\u4f1a\u8c03\u7528\u5b50View\u7684draw(Canvas canvas, ViewGroup parent, long drawingTime)\u65b9\u6cd5\uff0c\u8fdb\u800c\u518d\u8c03\u7528\u5b50View\u7684draw(Canvas canvas)\u65b9\u6cd5\uff0c\u5982\u6b64\u5faa\u73af\u9012\u5f52\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"View%E7%9A%84%E7%BB%98%E5%88%B6%E4%B8%8D%E4%BB%85%E4%BB%85%E6%98%AFonDraw%E6%96%B9%E6%B3%95\"><\/span>View\u7684\u7ed8\u5236\u4e0d\u4ec5\u4ec5\u662fonDraw\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u7ed3\u5408\u4e0a\u9762\u548c\u535a\u5ba2\u8fd8\u6709\u6e90\u7801\u5206\u6790\u53ef\u77e5\uff0conDraw\u53ea\u662f\u7ed8\u5236View\u7684content(\u5185\u5bb9\uff09\uff0c\u5e76\u4e0d\u80fd\u4ee3\u8868\u7ed8\u5236\u7684\u5168\u90e8\u3002draw\u7684\u8fc7\u7a0b\u5176\u5b9e\u6709\u5f88\u591a\u6b65\u9aa4\uff1a<br \/>\n- \u7b2c1\u6b65\uff1a\u7ed8\u5236\u80cc\u666f<br \/>\n\u8c03\u7528drawBackground(Canvas canvas)\u65b9\u6cd5<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-bacf13388f5dd96f.png\" alt=\"\" \/><br \/>\n\u8fd9\u4e2a\u65b9\u6cd5\u4f1a\u8c03\u7528\u80cc\u666fDrawable\u7684draw\u65b9\u6cd5\uff0c\u4e0d\u540c\u7684Drawable\u4f1a\u6709\u4e0d\u540c\u7684\u5b9e\u73b0\u3002<br \/>\n- \u7b2c3\u6b65\uff1a\u7ed8\u5236\u5185\u5bb9<br \/>\n\u8c03\u7528onDraw(Canvas canvas)\u65b9\u6cd5<br \/>\n- \u7b2c4\u6b65\uff1a\u7ed8\u5236\u5b50View<br \/>\n\u8c03\u7528dispatchDraw(Canvas canvas)\u65b9\u6cd5<br \/>\n- \u7b2c6\u6b65\uff1a\u7ed8\u5236\u524d\u666f<br \/>\n\u8c03\u7528onDrawForeground(Canvas canvas) \u65b9\u6cd5\uff0c<br \/>\n\u7ed8\u5236\u6eda\u52a8\u6307\u793a\u5668\uff1aonDrawScrollIndicators(canvas);<br \/>\n\u7ed8\u5236\u6eda\u52a8\u6761\uff1aonDrawScrollBars(canvas);<br \/>\n\u6700\u540e\uff0c\u548c\u7ed8\u5236\u80cc\u666f\u7c7b\u4f3c\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u4f1a\u8c03\u7528\u524d\u666fDrawable\u7684draw\u65b9\u6cd5\uff0c\u4e0d\u540c\u7684Drawable\u4f1a\u6709\u4e0d\u540c\u7684\u5b9e\u73b0\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E8%87%AA%E5%AE%9A%E4%B9%89View%E5%AE%9E%E8%B7%B5\"><\/span>\u81ea\u5b9a\u4e49View\u5b9e\u8df5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u4e0a\u9762\u5199\u4e86\u8fd9\u4e48\u591a\uff0c\u51c6\u5907\u518d\u5199\u4e00\u7bc7\u4e8b\u4ef6\u5206\u53d1\uff0c\u7136\u540e\u51fa\u4e00\u7bc7\u81ea\u5b9a\u4e49View\u5b9e\u8df5\u6587\u7ae0\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E7%BB%98%E5%88%B6%E5%86%B2%E7%AA%81\"><\/span>\u7ed8\u5236\u51b2\u7a81<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"1ScrollView%E4%B8%8EListView%E5%B5%8C%E5%A5%97%E5%86%B2%E7%AA%81%E7%9A%84%E9%97%AE%E9%A2%98\"><\/span>1.ScrollView\u4e0eListView\u5d4c\u5957\u51b2\u7a81\u7684\u95ee\u9898<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>ScrollView\u5d4c\u5957ListView\uff0c\u4f1a\u5bfc\u81f4ListView\u53ea\u663e\u793a\u4e00\u4e2aItem\u7684\u9ad8\u5ea6\uff0c \u65e0\u8bbaListView\u7684\u9ad8\u5ea6\u8bbe\u7f6e\u6210\u4efb\u4f55\u7684\u503c\uff08match\u3001wrap\u3001exactly\uff09\u90fd\u5982\u6b64\u3002\u8fd9\u91cc\u5c5e\u4e8eView\u7684\u7ed8\u5236\u51b2\u7a81\uff0c\u5c31\u4e0d\u5c5e\u4e8e\u4e8b\u4ef6\u51b2\u7a81\u4e86\uff0c\u4e0d\u8981\u641e\u6df7\u4e86\u3002<\/p>\n<p>\u7f51\u4e0a\u63d0\u4f9b\u4e86\u5404\u79cd\u89e3\u51b3\u529e\u6cd5\uff0c\u4e0b\u9762\u6211\u4ece\u6e90\u7801\u7684\u89d2\u5ea6\u5206\u6790\u5206\u6790\u5b9e\u8d28\u7684\u539f\u56e0\uff1a<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%85%88%E6%84%9F%E6%80%A7%E5%9C%B0%E5%86%99%E4%B8%80%E4%BA%9BDemo\"><\/span>\u5148\u611f\u6027\u5730\u5199\u4e00\u4e9bDemo<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u83b7\u53d6\u6d4b\u91cf\u6a21\u5f0f\u7684\u5de5\u5177\u7c7b<\/p>\n<pre><code class=\"language-java line-numbers\">public class CUtil {\n    public static String getMeasureModeName( int measureSpec){\n        int result = View.MeasureSpec.getMode(measureSpec);\n        if(View.MeasureSpec.UNSPECIFIED == result){\n            return \"UNSPECIFIED\";\n        }else if(View.MeasureSpec.EXACTLY == result){\n            return \"EXACTLY\";\n        }else if(View.MeasureSpec.AT_MOST == result){\n            return \"EXACTLY\";\n        }\n        return \"UNKNOWN\";\n    }\n}\n<\/code><\/pre>\n<p>\u81ea\u5b9a\u4e49\u4e00\u4e2aListView\uff0c\u6253\u5370\u6d4b\u91cf\u76f8\u5173\u7684\u65e5\u5fd7\u3002<\/p>\n<pre><code class=\"language-java line-numbers\">    @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        Log.e(TAG, \"onMeasure: \" + CUtil.getMeasureModeName(heightMeasureSpec));\n        super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n        int h  = getMeasuredHeightAndState();\n        Log.e(TAG, \"\u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: \"  + h);\n    }\n<\/code><\/pre>\n<ul>\n<li>Demo1:\u6709ScrollView\u5d4c\u5957<\/li>\n<\/ul>\n<pre><code class=\"language-java line-numbers\">&lt;com.example.eventdispatchdemo.scrollView.MyScrollView\n        android:id=\"@+id\/scrollView\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:background=\"@android:color\/holo_blue_bright\"\n        &gt;\n        &lt;com.example.eventdispatchdemo.scrollView.MyListView\n            android:id=\"@+id\/listview\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"\n            android:background=\"@android:color\/holo_red_dark\"\n            \/&gt;\n    &lt;\/com.example.eventdispatchdemo.scrollView.MyScrollView&gt;\n<\/code><\/pre>\n<p>\u8f93\u51fa\u65e5\u5fd7\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">MyListView: onMeasure: UNSPECIFIED\nMyListView: \u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 90\n<\/code><\/pre>\n<ul>\n<li>Demo2:\u6b63\u5e38\u60c5\u51b5\uff0c\u53ea\u6709ListView\u3002<\/li>\n<\/ul>\n<pre data-language=XML><code class=\"language-markup line-numbers\">     &lt;com.example.eventdispatchdemo.scrollView.MyListView\n            android:id=\"@+id\/listview\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"\n            android:background=\"@android:color\/holo_red_dark\"\n            \/&gt;\n<\/code><\/pre>\n<p>\u8f93\u51fa\u65e5\u5fd7\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">MyListView: onMeasure: EXACTLY\nMyListView: \u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 2088\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E6%89%BE%E5%88%B0%E7%AA%81%E7%A0%B4%E5%8F%A3%E5%88%86%E6%9E%90\"><\/span>\u627e\u5230\u7a81\u7834\u53e3\u5206\u6790<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u4ece\u4e0a\u9762\u7684\u65e5\u5fd7\u5206\u6790\u53ef\u77e5\uff0cScrollView\u7684\u5d4c\u5957\u5bfc\u81f4\u4e86ListView\u7684\u6d4b\u91cf\u6a21\u5f0f\u548c\u5927\u5c0f\u7684\u5f02\u5e38\uff0c\u6240\u4ee5\u76f4\u63a5\u5206\u6790ScrollView\u3002\u771f\u522b\u8bf4\uff0c\u6211\u5728ScrollView\u91cc\u7acb\u9a6c\u627e\u5230\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u89e3\u51b3\u95ee\u9898\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">   public void setFillViewport(boolean fillViewport) {\n        if (fillViewport != mFillViewport) {\n            mFillViewport = fillViewport;\n            requestLayout();\n        }\n    }\n<\/code><\/pre>\n<p>\u9ed8\u8ba4mFillViewport\u662ffalse\uff0c\u901a\u8fc7\u8c03\u7528setFillViewport\u5373\u53ef\u89e3\u51b3\u51b2\u7a81\u95ee\u9898\u3002<br \/>\n\u4f46\u662f\u4e0d\u7ba1\u7ed9ListView\u8bbe\u7f6e\u4ec0\u4e48\u9ad8\u5ea6\u5c5e\u6027\uff0cListView\u7684\u9ad8\u5ea6\u59cb\u7ec8\u662fmatch_parent\u7684\uff0c\u56e0\u4e3aListView\u8fdb\u884c\u7b2c\u4e8c\u6b21\u6d4b\u91cf\u3002<\/p>\n<ul>\n<li>#### \u5206\u6790ScrollView\u7684\u6d4b\u91cf\u6e90\u7801\uff08\u57fa\u4e8eAPI28\uff09\uff1a<\/li>\n<\/ul>\n<pre><code class=\"language-java line-numbers\">@Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n\n        if (!mFillViewport) {\n            return;\n        }\n        \/\/mFillViewport\u4e3atrue\u4f1a\u6267\u884c\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u5c06ChildView\u5168\u90e8\u8bbe\u7f6e\u4e3a\u548cScrollView\u4e00\u822c\u7684\u5927\u5c0f\u3002\n\n        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);\n        if (heightMode == MeasureSpec.UNSPECIFIED) {\n            return;\n        }\n\n        if (getChildCount() &gt; 0) {\n            final View child = getChildAt(0);\n            final int widthPadding;\n            final int heightPadding;\n            final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;\n            final FrameLayout.LayoutParams lp = (LayoutParams) child.getLayoutParams();\n            if (targetSdkVersion &gt;= VERSION_CODES.M) {\n                widthPadding = mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin;\n                heightPadding = mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin;\n            } else {\n                widthPadding = mPaddingLeft + mPaddingRight;\n                heightPadding = mPaddingTop + mPaddingBottom;\n            }\n\n            final int desiredHeight = getMeasuredHeight() - heightPadding;\n            if (child.getMeasuredHeight() &lt; desiredHeight) {\n                final int childWidthMeasureSpec = getChildMeasureSpec(\n                        widthMeasureSpec, widthPadding, lp.width);\n                final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(\n                        desiredHeight, MeasureSpec.EXACTLY);\n                child.measure(childWidthMeasureSpec, childHeightMeasureSpec);\n            }\n        }\n    }\n<\/code><\/pre>\n<p>\u6240\u4ee5\u6211\u4eec\u5c06\u76ee\u5149\u653e\u5230<\/p>\n<pre><code class=\"language-java line-numbers\">super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n<\/code><\/pre>\n<p>\u4e0a\uff0c\u4e5f\u5c31\u662fFrameLayout\u7684\u6d4b\u91cf\u3002\u901a\u8fc7\u6253\u5370MyScrollView\u7684\u65e5\u5fd7<\/p>\n<pre><code class=\"language-java line-numbers\">MyScrollView: onMeasure: w-EXACTLY,h-EXACTLY,isFillViewPort:true\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u53d1\u73b0\uff0cScrollView\u7684\u5bbd\u9ad8\u6d4b\u91cf\u6a21\u5f0f\u90fd\u662fEXACTLY(\u56e0\u4e3a\u5e03\u5c40\u662fmatch_parent)\uff0c\u800c\u6700\u7ec8MyListView\u6253\u5370\u7684\u9ad8\u5ea6\u6d4b\u91cf\u6a21\u5f0f\u662fUNSPECIFIED\uff0c\u90a3\u4e48\u8fd9\u4e2d\u95f4\u53c8\u6709\u600e\u6837\u7684\u6545\u4e8b\uff1f<br \/>\n\u5230\u6b64\u5904\uff0c<del>\u53ef\u80fd\u6709\u4eba\u5c31\u89c9\u5f97\u6ca1\u6709\u5fc5\u8981\u518d\u5206\u6790FrameLayout\u4e86\uff0c\u56e0\u4e3aFrameLayout\u5d4c\u5957ListView\u4e0d\u4f1a\u6709\u51b2\u7a81\u3002<\/del>\uff08<strong>\u5176\u5b9e\u8fd9\u662f\u4e2a\u9519\u8bef\u7684\u7406\u89e3<\/strong>\uff0c\u867d\u7136ScrollView\u662f\u8c03\u7528\u7684FrameLayout\u7684onMeasure\u65b9\u6cd5\uff0c\u4f46\u662fonMeasure\u65b9\u6cd5\u7684\u8fd0\u884c\u8f7d\u4f53\u8fd8\u662fScrollView\u3002\uff09<br \/>\n\u63a5\u7740\u770bFrameLayout\u7684\u6d4b\u91cf\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">  @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        ...\n        for (int i = 0; i &lt; count; i++) {\n            final View child = getChildAt(i);\n            if (mMeasureAllChildren || child.getVisibility() != GONE) {\n                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);\n                ...\n            }\n        }\n        ...\n    }\n<\/code><\/pre>\n<p>\u63a5\u7740\u70b9\u51fbmeasureChildWithMargins\u65b9\u6cd5\uff0c\u4f1a\u8df3\u8f6c\u5230ViewGroup\uff0c\u4e00\u76f4\u5f80\u4e0b\u5206\u6790\uff0c\u60f3\u7834\u4e86\u5934\u4e5f\u4e0d\u53ef\u80fd\u5f97\u51fa\u201cScrollView\u7684\u9ad8\u5ea6\u662fEXACTLY\uff0c\u5230\u4e86ListView\u7684\u6d4b\u91cf\u9ad8\u5ea6\u4e3aUNSPECIFIED\u201d\u7684\u7ed3\u8bba\u3002<br \/>\n\u675c\u5a18\u89e3\u51b3\u4e86\u6211\u7684\u7591\u60d1\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/u011247387\/article\/details\/90759338\">https:\/\/blog.csdn.net\/u011247387\/article\/details\/90759338<\/a><br \/>\n\u5176\u5b9e\uff0c<strong>ScrollView\u590d\u5199\u4e86measureChildWithMargins\u65b9\u6cd5<\/strong>\uff0c\u53ea\u662f\u4ee3\u7801\u8df3\u8f6c\u5230\u4e86ViewGroup\u3002<br \/>\n\u770bScrollView\u7684measureChildWithMargins\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\"> @Override\n    protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed,\n            int parentHeightMeasureSpec, int heightUsed) {\n        final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();\n\n        final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,\n                mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin\n                        + widthUsed, lp.width);\n        final int usedTotal = mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin +\n                heightUsed;\n        final int childHeightMeasureSpec = MeasureSpec.makeSafeMeasureSpec(\n                Math.max(0, MeasureSpec.getSize(parentHeightMeasureSpec) - usedTotal),\n                MeasureSpec.UNSPECIFIED);\n\n        child.measure(childWidthMeasureSpec, childHeightMeasureSpec);\n    }\n<\/code><\/pre>\n<p>\u679c\u7136\uff0c<strong>ScrollView\u4e3a\u5b50\u7c7b\u6307\u5b9a\u9ad8\u5ea6\u7684\u6d4b\u91cf\u6a21\u5f0f\u90fd\u662fUNSPECIFIED\u3002<\/strong><br \/>\n\u90a3\u4e48\u95ee\u9898\u5c31\u5728\u4e8e\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">MeasureSpec.getSize(parentHeightMeasureSpec) - usedTotal\n<\/code><\/pre>\n<p>\u4e3a\u4ec0\u4e48\u53ea\u7ed9ListView\u4e00\u884c\u7684item\u9ad8\u5ea6\uff1f<br \/>\n\u90a3\u8fd9\u4e2a\u503c\u5230\u5e95\u662f\u591a\u5c11\uff0c\u590d\u5199\u4e00\u4e0bMyScrollView\u7684measureChildWithMargins\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">  @Override\n    protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {\n        final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();\n        final int usedTotal = getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin +\n                heightUsed;\n        int ch = MeasureSpec.getSize(parentHeightMeasureSpec) - usedTotal;\n        Log.e(TAG, \"getPaddingTop: \" + getPaddingTop());\n        Log.e(TAG, \"getPaddingBottom: \" + getPaddingBottom());\n        Log.e(TAG, \"lp.topMargin: \" + lp.topMargin);\n        Log.e(TAG, \"lp.bottomMargin: \" + lp.bottomMargin);\n        Log.e(TAG, \"ch: \" + ch);\n        final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(\n                Math.max(0, MeasureSpec.getSize(parentHeightMeasureSpec) - usedTotal),\n                MeasureSpec.UNSPECIFIED);\n        Log.e(TAG, \"ch2: \" + MeasureSpec.getSize(childHeightMeasureSpec));\n        super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);\n    }\n<\/code><\/pre>\n<p>\u5bf9\u4e8eAPI23\u4ee5\u4e0a\u7684\u624b\u673a\uff0c\u6ce8\u610f\u4e0a\u9762\u7684makeMeasureSpec\u5e94\u8be5\u662fmakeSafeMeasureSpec\u65b9\u6cd5\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u4e2a\u65b9\u6cd5\u662fhide\uff0c\u9700\u8981\u901a\u8fc7\u53cd\u5c04\u8c03\u7528\u3002<\/p>\n<pre><code class=\"language-java line-numbers\">@Override\n    protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {\n        final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();\n        final int usedTotal = getPaddingTop() + getPaddingBottom() + lp.topMargin + lp.bottomMargin +\n                heightUsed;\n        int ch = MeasureSpec.getSize(parentHeightMeasureSpec) - usedTotal;\n        Log.e(TAG, \"getPaddingTop: \" + getPaddingTop());\n        Log.e(TAG, \"getPaddingBottom: \" + getPaddingBottom());\n        Log.e(TAG, \"lp.topMargin: \" + lp.topMargin);\n        Log.e(TAG, \"lp.bottomMargin: \" + lp.bottomMargin);\n        Log.e(TAG, \"ch: \" + ch);\n        int childHeightMeasureSpec = 0;\n        try {\n            childHeightMeasureSpec = (int) ReflectManger.invokeMethod(MeasureSpec.class,null,\"makeSafeMeasureSpec\",new Class[]{Integer.class,Integer.class},\n                    new Object[]{ Math.max(0, MeasureSpec.getSize(parentHeightMeasureSpec) - usedTotal),\n                            MeasureSpec.UNSPECIFIED}\n                    );\n        } catch (NoSuchMethodException e) {\n            e.printStackTrace();\n        } catch (InvocationTargetException e) {\n            e.printStackTrace();\n        } catch (IllegalAccessException e) {\n            e.printStackTrace();\n        }\n\n        Log.e(TAG, \"ch2: \" + MeasureSpec.getSize(childHeightMeasureSpec));\n        super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);\n    }\n<\/code><\/pre>\n<p>\u65e5\u5fd7\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">MyScrollView: onMeasure: w-EXACTLY,h-EXACTLY,i\nMyScrollView: getPaddingTop: 0\nMyScrollView: getPaddingBottom: 0\nMyScrollView: lp.topMargin: 0\nMyScrollView: lp.bottomMargin: 0\nMyScrollView: ch: 1557\nMyScrollView: ch2: 1557\nMyListView: onMeasure: UNSPECIFIED,\u6d4b\u91cf\u524d\u7684H size = 0\nMyListView: \u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 90\n<\/code><\/pre>\n<p>\u6240\u4ee5\uff0cScrollView\u662f\u65e0\u8f9c\u7684\uff0c\u5b83\u4f20\u9012\u7ed9ListView\u7684\u6d4b\u91cf\u9ad8\u5ea6\u786e\u5b9e\u662f1557\uff0c\u5230\u4e86ListView\uff0cListView\u6d4b\u91cf\u524d\u662f0\uff0c\u6d4b\u91cf\u540e\u5c31\u6210\u4e8690\u4e86\u3002\u90a3\u4e48\u6700\u6709\u53ef\u80fd\u5c31\u662fmeasure\u65b9\u6cd5\u641e\u7684\u9b3c\u4e86\uff0c\u8fd9\u4e2a\u5148\u653e\u4e00\u653e\u3002<\/p>\n<ul>\n<li>#### \u5206\u6790ListView\u7684\u6d4b\u91cf\u6e90\u7801\uff1a<\/li>\n<\/ul>\n<pre><code class=\"language-java line-numbers\"> @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        \/\/ Sets up mListPadding\n        super.onMeasure(widthMeasureSpec, heightMeasureSpec);\n\n        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);\n        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);\n        int widthSize = MeasureSpec.getSize(widthMeasureSpec);\n        int heightSize = MeasureSpec.getSize(heightMeasureSpec);\n\n        int childWidth = 0;\n        int childHeight = 0;\n        int childState = 0;\n\n        mItemCount = mAdapter == null ? 0 : mAdapter.getCount();\n        if (mItemCount &gt; 0 &amp;&amp; (widthMode == MeasureSpec.UNSPECIFIED\n                || heightMode == MeasureSpec.UNSPECIFIED)) {\n            final View child = obtainView(0, mIsScrap);\n\n            \/\/ Lay out child directly against the parent measure spec so that\n            \/\/ we can obtain exected minimum width and height.\n            measureScrapChild(child, 0, widthMeasureSpec, heightSize);\n\n            childWidth = child.getMeasuredWidth();\n            childHeight = child.getMeasuredHeight();                                      \/\/\u6d4b\u91cfItemView\u7684\u9ad8\u5ea6\n            ...\n        }\n        ...\n        if (heightMode == MeasureSpec.UNSPECIFIED) {                          \/\/\u83b7\u53d6ListView\u7684\u6d4b\u91cf\u9ad8\u5ea6\n            heightSize = mListPadding.top + mListPadding.bottom + childHeight +\n                    getVerticalFadingEdgeLength() * 2;\n        }\n\n        if (heightMode == MeasureSpec.AT_MOST) {\n            \/\/ TODO: after first layout we should maybe start at the first visible position, not 0\n            heightSize = measureHeightOfChildren(widthMeasureSpec, 0, NO_POSITION, heightSize, -1);\n        }\n\n        setMeasuredDimension(widthSize, heightSize);\n         ...\n    }\n<\/code><\/pre>\n<p>ListView\u7684\u6d4b\u91cf\u6a21\u5f0f\u88abScrollView\u6307\u5b9a\u4e3aUNSPECIFIED\uff0c\u90a3\u4e48ListView\u7684\u9ad8\u5ea6\u5c31\u662f\u7531<\/p>\n<pre><code class=\"line-numbers\">    if (heightMode == MeasureSpec.UNSPECIFIED) {                          \/\/\u83b7\u53d6ListView\u7684\u6d4b\u91cf\u9ad8\u5ea6\n            heightSize = mListPadding.top + mListPadding.bottom + childHeight +\n                    getVerticalFadingEdgeLength() * 2;\n  }\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u6765\u51b3\u5b9a\u7684\uff0cListView\u4e0d\u8bbe\u7f6e\u989d\u5916\u7684\u5c5e\u6027\u7684\u8bdd\uff0cheightSize\u5c31\u662f\u7b49\u4e8echildHeight\u7684\u9ad8\u5ea6\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%80%BB%E7%BB%93%EF%BC%9A\"><\/span>\u603b\u7ed3\uff1a<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<blockquote><p>\n  ScrollView\u4e0eListView\u5d4c\u5957\u51b2\u7a81\u7684\u95ee\u9898\uff0c\u5176\u5b9e\u662f\u4e00\u4e2a\u5171\u6027\u7684\u95ee\u9898\uff1a\u672c\u8d28\u4e0a\u5c31\u662fScrollView\u5f3a\u5236\u4e3a\u5b50View\u7684\u9ad8\u8bbe\u7f6e\u4e86UNSPECIFIED\u7684\u6d4b\u91cf\u6a21\u5f0f\uff0c\u5982\u679c\u5b50View\u7684\u9ad8\u9488\u5bf9UNSPECIFIED\u6d4b\u91cf\u6a21\u5f0f\u505a\u4e86\u7279\u6b8a\u5904\u7406\uff0c\u5c31\u4f1a\u53d1\u751f\u5947\u602a\u7684\u73b0\u8c61\uff0c\u6211\u4eec\u4e60\u60ef\u79f0\u4e4b\u4e3a\u51b2\u7a81\u3002\n<\/p><\/blockquote>\n<p>\u679c\u4e0d\u5947\u7136\uff0cScrollView\u5d4c\u5957\u5176\u5b83\u7684View\u4e5f\u4f1a\u51fa\u73b0\u95ee\u9898\uff0c\u4e0b\u9762\u5199\u51e0\u4e2aDemo\u7814\u7a76\u4e00\u4e0b:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"ScrollView%E5%B5%8C%E5%A5%97RelativeLayout%E5%86%B2%E7%AA%81%E7%A4%BA%E4%BE%8B1%EF%BC%9A\"><\/span>ScrollView\u5d4c\u5957RelativeLayout\u51b2\u7a81\u793a\u4f8b1\uff1a<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"%E7%8E%B0%E8%B1%A1\"><\/span>\u73b0\u8c61<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u300b\u300bMyRelativeLayout\u7684\u5e03\u5c40\u9ad8\u5ea6\u4e3amatch_parent\uff0cMyRelativeLayout\u7684\u4e0d\u663e\u793a\u3002<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-3ef9dd0bc57fc425.png\" alt=\"\" \/><br \/>\n\u6253\u5370\u65e5\u5fd7\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">MyRelativeLayout: onMeasure: UNSPECIFIED,\u6d4b\u91cf\u524d\u7684H size = 0\nMyRelativeLayout: \u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 0\n<\/code><\/pre>\n<p>\u300b\u300b\u5c06MyRelativeLayout\u7684\u5e03\u5c40\u9ad8\u5ea6\u5199\u6b7b\u6210100dp\uff0cMyRelativeLayout\u7684\u9ad8\u5ea6\u663e\u793a\u6b63\u5e38\u3002<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-e5e02970017c8fb1.png\" alt=\"\" \/><br \/>\n\u6253\u5370\u65e5\u5fd7\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">MyRelativeLayout: onMeasure: UNSPECIFIED,\u6d4b\u91cf\u524d\u7684H size = 0\nMyRelativeLayout: \u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 300\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"%E5%88%86%E6%9E%90RelativeLayout%E7%9A%84%E6%B5%8B%E9%87%8F%E6%96%B9%E6%B3%95%EF%BC%88%E6%B2%A1%E6%9C%89%E5%AD%90View%E7%9A%84%E6%83%85%E5%86%B5%EF%BC%89\"><\/span>\u5206\u6790RelativeLayout\u7684\u6d4b\u91cf\u65b9\u6cd5\uff08\u6ca1\u6709\u5b50View\u7684\u60c5\u51b5\uff09<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-java line-numbers\"> @Override\n    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\n        ...\n        int height = 0;\n        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);\n        final boolean isWrapContentHeight = heightMode != MeasureSpec.EXACTLY;   \/\/\u4e3atrue\n        ... \/\/\u4e2d\u95f4\u7701\u7565\u5b50View\u7684\u904d\u5386\n        if (isWrapContentHeight) {\n            \/\/ Height already has top padding in it since it was calculated by looking at\n            \/\/ the bottom of each child view\n            height += mPaddingBottom;\n            \/\/\u6211\u7ed9RelativeLayout\u8bbe\u7f6e\u4e86\u9ad8\u5ea6mLayoutParams.height &gt; 0\n            if (mLayoutParams != null &amp;&amp; mLayoutParams.height &gt;= 0) {\n                height = Math.max(height, mLayoutParams.height);\n            }\n            height = Math.max(height, getSuggestedMinimumHeight());\n            height = resolveSize(height, heightMeasureSpec);\n            ...\n            setMeasuredDimension(width, height);\n    }\n<\/code><\/pre>\n<p>RelativeLayout\u7684\u9ad8\u5ea6\u6a21\u5f0f\u4e3aUNSPECIFIED\uff0c\u4e14\u6ca1\u6709\u5b50View\uff0c\u90a3\u4e48\u5b83\u7684\u9ad8\u5ea6\u53d6\u51b3\u4e8e\u5b83\u7684\u5e03\u5c40\u53c2\u6570heigth\u662f\u5426\u5927\u4e8e0\u3002\u800cMATCH_PARENT = -1\uff0c\u6240\u4ee5RelativeLayout\u7684\u9ad8\u5ea6\u8bbe\u7f6e\u4e3aMATCH_PARENT\u7684\u65f6\u5019\u5b83\u4e0d\u663e\u793a\uff0c\u8bbe\u7f6e\u6210\u4e00\u4e2a\u5e38\u91cf\u5b83\u5c31\u663e\u793a\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"ScrollView%E5%B5%8C%E5%A5%97RelativeLayout%E5%86%B2%E7%AA%81%E7%A4%BA%E4%BE%8B2%EF%BC%9A\"><\/span>ScrollView\u5d4c\u5957RelativeLayout\u51b2\u7a81\u793a\u4f8b2\uff1a<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u300b\u300bMyRelativeLayout\u7684\u5e03\u5c40\u9ad8\u5ea6\u8fd8\u662fmatch_parent\uff0c\u7ed9MyRelativeLayout\u5d4c\u5957\u4e00\u4e2a\u5b50View\uff0c\u5b50View\u7684\u9ad8\u5ea6\u8bbe\u7f6e\u4e3aMATCH_PARENT\u3002\u5b50View\u548cMyRelativeLayout\u90fd\u4e0d\u663e\u793a\u3002<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-77c503c22a2179da.png\" alt=\"\" \/><br \/>\n\u8f93\u51fa\u65e5\u5fd7\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">MyRelativeLayout: onMeasure: UNSPECIFIED,\u6d4b\u91cf\u524d\u7684H size = 0\nMyView: onMeasure: UNSPECIFIED,\u6d4b\u91cf\u524d\u7684H size = 0\nMyView: \u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 0\nMyView: onMeasure: UNSPECIFIED,\u6d4b\u91cf\u524d\u7684H size = 0\nMyView: \u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 0\nMyRelativeLayout: \u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 0\n<\/code><\/pre>\n<p>\u53ef\u89c1\uff0cUNSPECIFIED\u5448\u73b0\u4e86\u4e00\u5b9a\u7684\u4f20\u9012\u6027\u3002<\/p>\n<h4><span class=\"ez-toc-section\" id=\"%E5%88%86%E6%9E%90RelativeLayout%E7%9A%84%E6%B5%8B%E9%87%8F%E6%96%B9%E6%B3%95%EF%BC%88%E6%9C%89%E5%AD%90View%E7%9A%84%E6%83%85%E5%86%B5%EF%BC%89\"><\/span>\u5206\u6790RelativeLayout\u7684\u6d4b\u91cf\u65b9\u6cd5\uff08\u6709\u5b50View\u7684\u60c5\u51b5\uff09<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u8bf7\u53c2\u7167<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.jianshu.com\/p\/8e3004494479\">https:\/\/www.jianshu.com\/p\/8e3004494479<\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"ScrollView%E5%B5%8C%E5%A5%97View%E5%86%B2%E7%AA%81%E7%A4%BA%E4%BE%8B%EF%BC%9A\"><\/span>ScrollView\u5d4c\u5957View\u51b2\u7a81\u793a\u4f8b\uff1a<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u300b\u300bMyRelativeLayout\u7684\u5e03\u5c40\u9ad8\u5ea6\u8fd8\u662fmatch_parent\uff0c\u5d4c\u5957\u4e00\u4e2aView(\u4e0d\u662fViewGroup)\u3002<br \/>\nView\u5373\u4f7f\u8bbe\u7f6e\u4e86\u9ad8\u5ea6\uff0c\u4e5f\u4e0d\u663e\u793a\u3002<br \/>\n<img src=\"http:\/\/122.152.205.50\/wordpress\/wp-content\/uploads\/jianshu_blog\/18328858-a5c718bcd90ca934.png\" alt=\"\" \/><br \/>\n\u8f93\u51fa\u65e5\u5fd7\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">onMeasure: UNSPECIFIED,\u6d4b\u91cf\u524d\u7684H size = 0\n\u6d4b\u91cf\u540e\u7684\u9ad8\u5ea6: 0\n<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"3971\" 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>https:\/\/www.jianshu.com\/p\/5baa20d3d953 \uff08\u6211\u5728\u7b80\u4e66\u4e0a\u7684\u6587\u7ae0\uff09  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[124],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/3971"}],"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=3971"}],"version-history":[{"count":9,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/3971\/revisions"}],"predecessor-version":[{"id":3977,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/3971\/revisions\/3977"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3971"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}