{"id":928,"date":"2022-02-23T14:56:57","date_gmt":"2022-02-23T06:56:57","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=928"},"modified":"2022-02-23T14:56:57","modified_gmt":"2022-02-23T06:56:57","slug":"reactnative%e5%88%9d%e4%bd%93%e9%aa%8cflex%e7%af%87%e4%b8%89","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=928","title":{"rendered":"ReactNative\u521d\u4f53\u9a8cflex\u7bc7(\u4e09)"},"content":{"rendered":"\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u4f7f\u7528flexDirection\u3001alignItems\u548c&nbsp;justifyContent\u4e09\u4e2a\u6837\u5f0f\u5c5e\u6027\u5c31\u5df2\u7ecf\u80fd\u6ee1\u8db3\u5927\u591a\u6570\u5e03\u5c40\u9700\u6c42\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/reactnative.cn\/docs\/flexbox\">https:\/\/reactnative.cn\/docs\/flexbox<\/a><br>\u5907\u6ce8\uff1a1.flex\u5185\u90e8\u53ef\u591a\u5c42\u5d4c\u5957\u30022.felx\u603b\u9ad8\u5ea6\u56fa\u5b9a\uff0c\u5b50\u9009\u9879\u8d85\u51fa\u5219\u9876\u51fa\u53bb\u4e0d\u4f1a\u5f71\u54cdflex\u5bb9\u5668\u53d8\u5316\u30023.felx\u9ad8\u5ea6\u4e0d\u786e\u5b9a\u65f6\uff0c\u4f1a\u9009\u62e9\u9ad8\u5ea6\u6700\u9ad8\u7684\u5b50\u9009\u62e9\u9ad8\u5ea6\u6491\u5f00\u3002<br><strong>(3)felx example\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import React, {Component} from \"react\";\nimport {StyleSheet, View, Text} from \"react-native\";\n\n\/**\n * Created by marno on 2022\/2\/22.\n * Desc:\u6a21\u62df\u9ab0\u5b50\u8fdb\u884c\u5e03\u5c40\uff0c\u7b97\u662fFlex\u5e03\u5c40\u5404\u7c7b\u5c5e\u6027\u7684\u5b9e\u6218\n *\/\nexport default class FlexDiceTest extends Component {\n    render() {\n        return (\n            &lt;View style={FlexDiceTestStyle.container}>\n                &lt;Text style={FlexDiceTestStyle.item1}>1&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item2}>2&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item3}>3&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item4}>4&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item5}>5&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item6}>6&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item7}>7&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item8}>8&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item9}>9&lt;\/Text>\n                &lt;Text style={FlexDiceTestStyle.item10}>10&lt;\/Text>\n            &lt;\/View>\n        )\n    }\n}\n\nconst FlexDiceTestStyle = StyleSheet.create({\n    container: {\n        backgroundColor: \"blue\",\n        height: 450,\n        width: 300,\n\/\/\u8bbe\u7f6e\u4e3b\u8f74\uff08\u6a2a\u8f74\uff09\u5bf9\u9f50\u65b9\u5f0f--\u4e24\u7aef\u5bf9\u9f50\uff0c\u9879\u76ee\u95f4\u9694\u76f8\u7b49\u3002\n        justifyContent: \"space-between\",\n\/\/\u89c4\u5b9aflex\u5bb9\u5668\u662f\u5355\u884c\u6216\u8005\u591a\u884c--\u6362\u884c\uff0c\u9996\u884c\u5728\u4e0a\u3002\n        flexWrap: \"wrap\",\n\/\/\u5e03\u5c40\u65b9\u5411---\u6c34\u5e73\u4ece\u5de6\u5230\u53f3\u3002\n        flexDirection: \"row\",\n    },\n    item1: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 140,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item2: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 140,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item3: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 90,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item4: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 90,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item5: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 90,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item6: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 290,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item7: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 80,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item8: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 80,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item9: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 80,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    },\n    item10: {\n        color: \"#fff\",\n        backgroundColor: \"#000\",\n        height: 80,\n        width: 290,\n        textAlign: \"center\",\n        textAlignVertical: \"center\",\n        margin: 4,\n    }\n})\n<\/code><\/pre>\n\n\n\n<p>\u9884\u89c8\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2022\/02\/image4.png\" alt=\"\" class=\"wp-image-929\" width=\"235\" height=\"375\" srcset=\"http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2022\/02\/image4.png 562w, http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2022\/02\/image4-188x300.png 188w\" sizes=\"(max-width: 235px) 100vw, 235px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u822c\u6765\u8bf4\uff0c\u4f7f\u7528flexDirection\u3001alignItems\u548c&nbsp;justifyContent\u4e09\u4e2a\u6837 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[40,1],"tags":[39],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/928"}],"collection":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=928"}],"version-history":[{"count":1,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/928\/revisions"}],"predecessor-version":[{"id":930,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/928\/revisions\/930"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=928"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}