{"id":484,"date":"2023-02-25T14:04:03","date_gmt":"2023-02-25T06:04:03","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=484"},"modified":"2023-04-29T20:52:06","modified_gmt":"2023-04-29T12:52:06","slug":"react-native-learning-view-component","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/react-native-learning-view-component\/","title":{"rendered":"React Native\u5b66\u4e60\u4e4bView\u7ec4\u4ef6"},"content":{"rendered":"<p>\u5728React Native\u91cc\u6709\u4e00\u4e2a\u7c7b\u4f3c\u4e8ediv\u7684\u7ec4\u4ef6\uff0c\u90a3\u5c31\u662fView\u7ec4\u4ef6\uff0c\u652f\u6301\u591a\u5c42\u5d4c\u5957\uff0c\u652f\u6301flexbox\u5e03\u5c40<\/p>\n<p>\u5b9e\u4f8b\u6b65\u9aa4\uff1a<\/p>\n<h3>\u52a0\u8f7dView\u7ec4\u4ef6<\/h3>\n<p><!-- more --><\/p>\n<h3>\u521b\u5efa\u7ec4\u4ef6<\/h3>\n<h3>\u6dfb\u52a0\u6837\u5f0f\u8868<\/h3>\n<h3>\u6ce8\u518c\u5165\u53e3<\/h3>\n<h3>\u5916\u5c42\u5e03\u5c40<\/h3>\n<pre><code class=\"language-html\">&lt;View style={styles.container}&gt;\n\n    &lt;View style={styles.item}&gt;&lt;\/View&gt;\n    &lt;View style={styles.item}&gt;&lt;\/View&gt;\n    &lt;View style={styles.item}&gt;&lt;\/View&gt;\n\n&lt;\/View&gt;<\/code><\/pre>\n<h3>Flexbox\u6c34\u5e73\u4e09\u680f\u5e03\u5c40<\/h3>\n<p>\u5916\u8054\u6837\u5f0f\uff1a<\/p>\n<pre><code class=\"language-html\">style={styles.container}<\/code><\/pre>\n<p>\u5185\u8054\u6837\u5f0f\uff1a<\/p>\n<pre><code class=\"language-html\">style={{flex:1, borderWidth:1, borderColor:&#039;red&#039;, flexDirection:&#039;row&#039;}}<\/code><\/pre>\n<p>\u591a\u4e2a\u6837\u5f0f\uff1a<\/p>\n<pre><code class=\"language-html\">style={[styles.container, styles.flex, {borderWidth:1,borderColor:&#039;red&#039;}]}<\/code><\/pre>\n<h3>\u4e0a\u4e0b\u4e24\u680f\u5e03\u5c40<\/h3>\n<pre><code class=\"language-html\">&lt;View style={[styles.center, styles.flex]}&gt;\n    &lt;Text&gt;\u56e2\u8d2d&lt;\/Text&gt;\n&lt;\/View&gt;\n\n&lt;View style={[styles.center, styles.flex]}&gt;\n    &lt;Text&gt;\u5ba2\u6808\uff0c\u516c\u5bd3&lt;\/Text&gt;\n&lt;\/View&gt;<\/code><\/pre>\n<h3>\u5b8c\u5584\u6548\u679c<\/h3>\n<pre><code class=\"language-html\">&lt;View style={[styles.item, styles.lineLeftRight]}&gt;\n    &lt;View style={[styles.center, styles.flex, styles.lineCenter]}&gt;\n        &lt;Text style={styles.font}&gt;\u6d77\u5916\u9152\u5e97&lt;\/Text&gt;\n    &lt;\/View&gt;\n\n    &lt;View style={[styles.center, styles.flex]}&gt;\n        &lt;Text style={styles.font}&gt;\u7279\u60e0\u9152\u5e97&lt;\/Text&gt;\n    &lt;\/View&gt;\n&lt;\/View&gt;<\/code><\/pre>\n<h3>\u7c97\u7cd9\u6548\u679c\u4ee3\u7801<\/h3>\n<pre><code class=\"language-javascript\">\/**\n * Sample React Native App\n * https:\/\/github.com\/facebook\/react-native\n *\/\n&#039;use strict&#039;;\nimport React, {\n  AppRegistry,\n  Component,\n  StyleSheet,\n  Text,\n  View\n} from &#039;react-native&#039;;\n\nclass RNAPP extends Component {\n  render() {\n    return (\n      &lt;View style={styles.container}&gt;\n        &lt;View style={[styles.item, styles.center]}&gt;\n          &lt;Text&gt;\u9152\u5e97&lt;\/Text&gt;\n        &lt;\/View&gt;\n\n        &lt;View style={styles.item}&gt;\n          &lt;View style={[styles.center, styles.flex]}&gt;\n            &lt;Text&gt;\u6d77\u5916\u9152\u5e97&lt;\/Text&gt;\n          &lt;\/View&gt;\n          &lt;View style={[styles.center, styles.flex]}&gt;\n            &lt;Text&gt;\u7279\u60e0\u9152\u5e97&lt;\/Text&gt;\n          &lt;\/View&gt;\n        &lt;\/View&gt;\n\n        &lt;View style={styles.item}&gt;\n          &lt;View style={[styles.center, styles.flex]}&gt;\n            &lt;Text&gt;\u56e2\u8d2d&lt;\/Text&gt;\n          &lt;\/View&gt;\n          &lt;View style={[styles.center, styles.flex]}&gt;\n            &lt;Text&gt;\u5ba2\u6808\uff0c\u516c\u5bd3&lt;\/Text&gt;\n          &lt;\/View&gt;\n        &lt;\/View&gt;\n      &lt;\/View&gt;\n    );\n  }\n}\n\nconst styles = StyleSheet.create({\n  container: {\n    flex:1,\n    borderWidth:1,\n    borderColor:&#039;red&#039;,\n    flexDirection:&#039;row&#039;,\n  },\n  item: {\n    flex: 1,\n    height:80,\n    borderColor:&#039;blue&#039;,\n    borderWidth:1,\n  },\n  center:{\n    justifyContent:&#039;center&#039;,\n    alignItems:&#039;center&#039;,\n  },\n  flex:{\n    flex:1,\n  },\n});\n\nAppRegistry.registerComponent(&#039;RNAPP&#039;, () =&gt; RNAPP);<\/code><\/pre>\n<h3>\u4f18\u5316\u540e\u7684\u6548\u679c\u4ee3\u7801<\/h3>\n<pre><code class=\"language-javascript\">\/**\n * Sample React Native App\n * https:\/\/github.com\/facebook\/react-native\n *\/\n&#039;use strict&#039;;\nimport React, {\n  AppRegistry,\n  Component,\n  StyleSheet,\n  PixelRatio,\n  Text,\n  View\n} from &#039;react-native&#039;;\n\nclass RNAPP extends Component {\n  render() {\n    return (\n      &lt;View style={styles.flex}&gt;\n        &lt;View style={styles.container}&gt;\n          &lt;View style={[styles.item, styles.center]}&gt;\n            &lt;Text style={styles.font}&gt;\u9152\u5e97&lt;\/Text&gt;\n          &lt;\/View&gt;\n\n          &lt;View style={[styles.item, styles.lineLeftRight]}&gt;\n            &lt;View style={[styles.center, styles.flex, styles.lineCenter]}&gt;\n              &lt;Text style={styles.font}&gt;\u6d77\u5916\u9152\u5e97&lt;\/Text&gt;\n            &lt;\/View&gt;\n            &lt;View style={[styles.center, styles.flex]}&gt;\n              &lt;Text style={styles.font}&gt;\u7279\u60e0\u9152\u5e97&lt;\/Text&gt;\n            &lt;\/View&gt;\n          &lt;\/View&gt;\n\n          &lt;View style={styles.item}&gt;\n            &lt;View style={[styles.center, styles.flex, styles.lineCenter]}&gt;\n              &lt;Text style={styles.font}&gt;\u56e2\u8d2d&lt;\/Text&gt;\n            &lt;\/View&gt;\n            &lt;View style={[styles.center,styles.flex]}&gt;\n              &lt;Text style={styles.font}&gt;\u5ba2\u6808\uff0c\u516c\u5bd3&lt;\/Text&gt;\n            &lt;\/View&gt;\n          &lt;\/View&gt;\n        &lt;\/View&gt;\n      &lt;\/View&gt;\n    );\n  }\n}\n\nconst styles = StyleSheet.create({\n  container: {\n    marginTop:200,\n    marginLeft:5,\n    marginRight:5,\n    height:84,\n    flexDirection:&#039;row&#039;,\n    borderRadius:5,\n    padding:2,\n    backgroundColor:&#039;#FF0067&#039;,\n  },\n  item: {\n    flex: 1,\n    height:80,\n\n  },\n  center:{\n    justifyContent:&#039;center&#039;,\n    alignItems:&#039;center&#039;,\n  },\n  flex:{\n    flex:1,\n  },\n  font:{\n    color:&#039;#fff&#039;,\n    fontSize:16,\n    fontWeight:&#039;bold&#039;,\n  },\n  lineLeftRight:{\n    borderLeftWidth:1\/PixelRatio.get(),\n    borderRightWidth:1\/PixelRatio.get(),\n    borderColor:&#039;#fff&#039;,\n  },\n  lineCenter:{\n    borderBottomWidth:1\/PixelRatio.get(),\n    borderColor:&#039;#fff&#039;,\n  },\n});\n\nAppRegistry.registerComponent(&#039;RNAPP&#039;, () =&gt; RNAPP);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728React Native\u91cc\u6709\u4e00\u4e2a\u7c7b\u4f3c\u4e8ediv\u7684\u7ec4\u4ef6\uff0c\u90a3\u5c31\u662fView\u7ec4\u4ef6\uff0c\u652f\u6301\u591a\u5c42\u5d4c\u5957\uff0c\u652f\u6301flexbox\u5e03\u5c40 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[163],"tags":[],"class_list":["post-484","post","type-post","status-publish","format-standard","hentry","category-react-native"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=484"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}