{"id":263,"date":"2017-04-18T18:29:25","date_gmt":"2017-04-18T18:29:25","guid":{"rendered":"https:\/\/boochlin.com\/?p=263"},"modified":"2017-04-18T18:29:25","modified_gmt":"2017-04-18T18:29:25","slug":"android-issue-ui%e4%bd%88%e5%b1%80%e8%a2%ab%e9%8d%b5%e7%9b%a4%e6%93%8b%e4%bd%8f","status":"publish","type":"post","link":"https:\/\/boochlin.com\/?p=263","title":{"rendered":"Android issue &#8211; UI\u4f48\u5c40\u88ab\u9375\u76e4\u64cb\u4f4f"},"content":{"rendered":"<p><a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/Screenshot_20170419-012205.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-286 aligncenter\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/Screenshot_20170419-012205.png\" alt=\"Screenshot_20170419-012205\" width=\"213\" height=\"381\" \/><\/a><\/p>\n<p>\u5176\u5be6\u9019\u554f\u984c\u6211\u4e5f\u4e0d\u77e5\u9053\u6709\u4eba\u770b\u5f97\u61c2\u55ce\uff1f\u4e0d\u904e\u51fa\u65bc\u81ea\u6211\u7d00\u9304\u7684 blog \u7684\u6982\u5ff5\uff0c\u5beb\u5beb\u770b\u3002<span style=\"color: #ff0000;\">\u4e3b\u8981\u5c31\u662f\u7576\u4f60\u8f38\u5165 EditText \u7684\u6642\u5019\uff0c\u901a\u5e38 android \u7cfb\u7d71\u6703\u81ea\u52d5\u8df3\u51fa soft keyboard\uff0c\u65b9\u4fbf\u4f7f\u7528\u8005\u8f38\u5165\uff0c\u4f46\u662f\u6709\u4e9b\u4f48\u5c40\uff0c\u5f48\u51fa\u4f86\u7684 keyboard \u6703\u64cb\u4f4f EditText \u7684\u8f38\u5165\u5321\uff0c\u8b93\u4f7f\u7528\u8005\u770b\u4e0d\u5230\u3002<\/span><\/p>\n<p>\u8001\u5be6\u8aaa\u9019\u6a23\u7684\u554f\u984c\uff0c\u6709\u4e00\u767e\u7a2e\u51fa\u73fe\u7684 UI\uff0c\u5c31\u53ef\u80fd\u6703\u6709\u4e00\u767e\u7a2e\u7684\u554f\u984c\u6839\u6e90\uff0c\u5f88\u591a\u60c5\u6cc1\u4e0b\u53ef\u80fd\u8981\u5f88 UI\/UX \u7684\u8a2d\u8a08\u5e2b\u8a0e\u8ad6\u3002\u57fa\u672c\u4e0a\u5f88\u96e3\u6709\u9280\u5f48\u53bb\u89e3\u6c7a\u6240\u6709\u7684\u554f\u984c\u3002<\/p>\n<p><!--more-->\u6211\u7684\u60c5\u6cc1\u5247\u662f\u5982\u5716\u6240\u793a\uff0c \u6c92\u6709\u51fa\u73fe\u9375\u76e4\u6642\uff0c\u756b\u9762\u5982\u4e0b\uff0c\u770b\u8d77\u4f86\u6c92\u6709\u554f\u984c\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/Screenshot_20170419-011818.png\"><img decoding=\"async\" class=\"alignnone wp-image-285\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/Screenshot_20170419-011818.png\" alt=\"Screenshot_20170419-011818\" width=\"247\" height=\"439\" \/><\/a><\/p>\n<p>\u4f46\u662f\u7576\u6211\u9ede\u64ca 2 \u865f\u8f38\u5165\u5321\u5f8c\u5c31\u63db\u81ea\u52d5\u8dd1\u51fa\u9375\u76e4\uff0c\u5982\u4e0b<\/p>\n<p><a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/Screenshot_20170419-012205.png\"><img decoding=\"async\" class=\"alignnone wp-image-286\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/Screenshot_20170419-012205.png\" alt=\"Screenshot_20170419-012205\" width=\"257\" height=\"457\" \/><\/a><\/p>\n<p>\u6709\u6c92\u6709\u767c\u73fe\uff0c\u9375\u76e4\u756b\u9762\u64cb\u4f4f\u4e86 2 \u865f\u8f38\u5165\u5321\uff0c\u901a\u5e38\u60c5\u6cc1\u5982\u679c\u662f\u4f7f\u7528 RecycleView \uff0c\u7cfb\u7d71\u6703\u81ea\u52d5\u6ed1\u5230 2 \u865f\u8f38\u5165\u5321\uff0c\u65b9\u4fbf\u4f7f\u7528\u8005\u8f38\u5165\uff0c\u800c\u4e0d\u662f\u88ab\u9375\u76e4\u84cb\u4f4f\u3002\u4e0d\u904e\u7531\u65bc\u6211\u7684\u4f48\u5c40\u7a0d\u5fae\u8907\u96dc\u4e00\u9ede\uff0c\u641e\u5f97\u4e0d\u6703\u81ea\u52d5\u6ed1\u904e\u53bb\u3002\u4e0d\u904e\u5176\u5be6\u4e5f\u5c31\u662f <span style=\"color: #0000ff;\">Activity with ViewPager(RecycleView inside Fragment) and Bottom TabLayout\u3002<\/span><\/p>\n<p>\u5982\u679c\u8981\u8ac7\u6df1\u4e00\u9ede\u5c31\u662f<\/p>\n<ol>\n<li>\u5982\u679c manifest \u6709\u8a2d\u5b9a\uff1a<span style=\"color: #0000ff;\"><a class=\"replace_word\" style=\"color: #0000ff;\" title=\"Android\u77e5\u8bc6\u5e93\" href=\"http:\/\/lib.csdn.net\/base\/android\" target=\"_blank\">Android<\/a>:windowSoftInputMode = &#8220;adjustResize&#8221;<\/span>\uff0c keyboard \u51fa\u73fe\u6642 app \u6703\u8abf\u7528\u00a0<span style=\"color: #0000ff;\">onSizeChanged<\/span>\uff0c\u6240\u4ee5\u6709\u4e9b\u4eba\u4f5c\u6cd5\u5c31\u662f\u5728\u9019\u8655\u7406\uff0c\u5c07\u756b\u9762\u7269\u4ef6\u91cd\u65b0\u6574\u7406\u3002<\/li>\n<li>\u4e5f\u6709\u4eba\u505a\u6cd5\u662f\u5229\u7528 <span style=\"color: #0000ff;\">OnGlobalLayoutListener<\/span> \u76e3\u807d\u756b\u9762\u8b8a\u5316\uff0c\u5229\u7528\u756b\u9762\u9ad8\u5ea6\u5224\u65b7\u662f\u5426\u9375\u76e4\u6709\u51fa\u73fe\u55ce\uff1f\u7136\u5f8c\u91cd\u65b0\u8abf\u6574\u756b\u9762\u7269\u4ef6\u914d\u7f6e\u3002<\/li>\n<\/ol>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/2150078\/how-to-check-visibility-of-software-keyboard-in-android\">http:\/\/stackoverflow.com\/questions\/2150078\/how-to-check-visibility-of-software-keyboard-in-android<\/a><\/p>\n<pre>final View activityRootView = findViewById(R.id.activityRoot);\r\nactivityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {\r\n    @Override\r\n    public void onGlobalLayout() {\r\n        int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();\r\n        if (heightDiff &gt; dpToPx(this, 200)) { \/\/ if more than 200 dp, it's probably a keyboard...\r\n            \/\/ ... do something here\r\n        }\r\n     }\r\n});\r\n<\/pre>\n<p>\u4e0d\u904e\u8001\u5be6\u8aaa\uff0c\u4e0a\u9762\u5169\u7a2e\u505a\u6cd5\u90fd\u9700\u8981\u914d\u5408 UI\/UX \u7684\u9375\u76e4\u756b\u9762\u642d\u914d\u8a2d\u8a08\uff0c\u9019\u61c9\u8a72\u662f\u6700\u4f73\u89e3\u3002\u4f46\u662f\u6211\u4e26\u6c92\u6709\u90a3\u9ebc\u591a\u8cc7\u6e90\uff0c\u6240\u4ee5\u53ea\u6253\u7b97\u505a\u51fa\u8f38\u5165\u5321\u53ef\u4ee5\u81ea\u52d5\u6ed1\u52d5\u5230\u4f7f\u7528\u8005\u80fd\u770b\u5230\u7684\u5730\u65b9\u3002<\/p>\n<p>\u6700\u5f8c\u6211\u5565\u9b3c\u90fd\u8a66\u904e\uff0c\u767c\u73fe\u53ea\u8981 RecycleView \u4e0a\u5916\u5c64\u52a0\u4e00\u500b <span style=\"color: #0000ff;\">NestedScrollView<\/span>\uff0c\u4e26\u8abf\u6574\u4e00\u4e0b ImageView \u7684\u4f4d\u5b50\u5c31\u53ef\u4ee5\u9054\u5230\u6548\u679c\u3002<\/p>\n<p><a href=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/\u87a2\u5e55\u5feb\u7167-2017-04-19-\u4e0a\u53482.09.44.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-287\" src=\"https:\/\/boochlin.com\/wp-content\/uploads\/2017\/04\/\u87a2\u5e55\u5feb\u7167-2017-04-19-\u4e0a\u53482.09.44.png\" alt=\"\u87a2\u5e55\u5feb\u7167 2017-04-19 \u4e0a\u53482.09.44\" width=\"1908\" height=\"952\" \/><\/a><\/p>\n<p><a href=\"https:\/\/developer.android.com\/reference\/android\/support\/v4\/widget\/NestedScrollView.html\">https:\/\/developer.android.com\/reference\/android\/support\/v4\/widget\/NestedScrollView.html<\/a><\/p>\n<p>\u611f\u8b1d\u5404\u4f4d\u770b\u5230\u9019\u88e1\uff0c\u4e5f\u53ea\u80fd\u8ac7\u5230\u9019\u88e1\uff0c\u7562\u7adf\u9019\u6709\u9ede\u500b\u4eba\u5316\u7684\u554f\u984c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5176\u5be6\u9019\u554f\u984c\u6211\u4e5f\u4e0d\u77e5\u9053\u6709\u4eba\u770b\u5f97\u61c2\u55ce\uff1f\u4e0d\u904e\u51fa\u65bc\u81ea\u6211\u7d00\u9304\u7684 blog \u7684\u6982\u5ff5\uff0c\u5beb\u5beb\u770b\u3002\u4e3b\u8981\u5c31\u662f\u7576\u4f60\u8f38\u5165 EditText \u7684\u6642\u5019\uff0c\u901a\u5e38 android \u7cfb\u7d71\u6703\u81ea\u52d5\u8df3\u51fa soft keyboard\uff0c\u65b9\u4fbf\u4f7f\u7528\u8005&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,5],"tags":[6,48,74],"_links":{"self":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/263"}],"collection":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=263"}],"version-history":[{"count":0,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions"}],"wp:attachment":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}