{"id":493,"date":"2023-02-25T14:12:46","date_gmt":"2023-02-25T06:12:46","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=493"},"modified":"2023-04-29T20:50:14","modified_gmt":"2023-04-29T12:50:14","slug":"react-native-learning-viewpagerandroid-component","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/react-native-learning-viewpagerandroid-component\/","title":{"rendered":"React Native\u5b66\u4e60\u4e4bViewPagerAndroid\u7ec4\u4ef6"},"content":{"rendered":"<p>\u4e00\u4e2a\u5141\u8bb8\u5728\u5b50\u89c6\u56fe\u4e4b\u95f4\u5de6\u53f3\u7ffb\u9875\u7684\u5bb9\u5668\u3002\u6bcf\u4e00\u4e2a<code>ViewPagerAndroid<\/code>\u7684\u5b50\u5bb9\u5668\u4f1a\u88ab\u89c6\u4f5c\u4e00\u4e2a\u5355\u72ec\u7684\u9875\uff0c\u5e76\u4e14\u4f1a\u88ab\u62c9\u4f38\u586b\u6ee1ViewPagerAndroid\u3002<\/p>\n<blockquote>\n<p>\u6ce8\u610f\u6240\u6709\u7684\u5b50\u89c6\u56fe\u90fd\u5fc5\u987b\u662f\u7eafView\uff0c\u800c\u4e0d\u80fd\u662f\u81ea\u5b9a\u4e49\u7684\u590d\u5408\u5bb9\u5668\u3002<\/p>\n<\/blockquote>\n<p><!-- more --><\/p>\n<h3>ViewPagerAndroid\u7ec4\u4ef6\u7684\u5c5e\u6027<\/h3>\n<ul>\n<li><code>initialPage<\/code>\uff1a\u521d\u59cb\u9009\u4e2d\u9875\u7684\u4e0b\u6807<\/li>\n<\/ul>\n<h3>ViewPagerAndroid\u7ec4\u4ef6\u7684\u65b9\u6cd5<\/h3>\n<p>1)\u3001<code>onPageScroll<\/code><\/p>\n<p>\u5f53\u5728\u9875\u95f4\u5207\u6362\u65f6\uff08\u4e0d\u8bba\u662f\u7531\u4e8e\u52a8\u753b\u8fd8\u662f\u7531\u4e8e\u7528\u6237\u5728\u9875\u95f4\u6ed1\u52a8\/\u62d6\u62fd\uff09\u6267\u884c\u3002<\/p>\n<p>\u56de\u8c03\u53c2\u6570\u4e2d\u7684event.nativeEvent\u5bf9\u8c61\u4f1a\u5305\u542b\u5982\u4e0b\u6570\u636e\uff1a<br \/>\nposition offset \u4e00\u4e2a\u5728[0,1)\uff08\u5927\u4e8e\u7b49\u4e8e0\uff0c\u5c0f\u4e8e1\uff09\u4e4b\u95f4\u7684\u8303\u56f4\uff0c\u4ee3\u8868\u5f53\u524d\u9875\u9762\u5207\u6362\u7684\u72b6\u6001\u3002<\/p>\n<p>2)\u3001<code>onPageScrollStateChanged<\/code><\/p>\n<p>\u72b6\u6001\u5305\u542b\uff1aidle dragging settling<\/p>\n<p>3)\u3001<code>onPageSelected<\/code><\/p>\n<p>\u5728\u9875\u9762\u5207\u6362\u5b8c\u6210\u540e\uff08\u5f53\u7528\u6237\u5728\u9875\u9762\u95f4\u6ed1\u52a8\uff09\u8c03\u7528\u3002<\/p>\n<p>\u56de\u8c03\u53c2\u6570\u4e2d\u7684event.nativeEvent\u5bf9\u8c61\u4f1a\u5305\u542b\u5982\u4e0b\u7684\u5b57\u6bb5\uff1a position<\/p>\n<p>4)\u3001<code>scrollEnabled<\/code><\/p>\n<p>boolean\u7c7b\u578b\uff0c\u8bbe\u7f6e\u4e3atrue\u5373\u53ef\u6ed1\u52a8\u3002<\/p>\n<pre><code class=\"language-javascript\">\/**\n * Sample React Native App\n * https:\/\/github.com\/facebook\/react-native\n *\/\n&#039;use strict&#039;;\n\nimport React, { Component } from &#039;react&#039;;\nimport {\n    AppRegistry,\n    StyleSheet,\n    Text,\n    ViewPagerAndroid,\n    View\n} from &#039;react-native&#039;;\n\nclass RNAPP extends Component {\n    render() {\n        return (\n            &lt;ViewPagerAndroid\n                initialPage={0}\n                style={[styles.flex, styles.viewpager]}\n                &gt;\n                &lt;View style={styles.center}&gt;\n                   &lt;Text style={[{fontSize:12}, {color:&#039;red&#039;}]}&gt;\u7b2c\u4e00\u4e2a\u9875\u9762&lt;\/Text&gt;\n                &lt;\/View&gt;\n                &lt;View style={styles.center}&gt;\n                    &lt;Text style={{fontSize:20}}&gt;\u7b2c\u4e8c\u4e2a\u9875\u9762&lt;\/Text&gt;\n                &lt;\/View&gt;\n                &lt;View style={styles.center}&gt;\n                    &lt;Text style={{fontSize:30}}&gt;\u7b2c\u4e09\u4e2a\u9875\u9762&lt;\/Text&gt;\n                &lt;\/View&gt;\n\n            &lt;\/ViewPagerAndroid&gt;\n        );\n    }\n}\n\nconst styles = StyleSheet.create({\n    flex:{\n        flexDirection:&#039;column&#039;,\n    },\n    viewpager:{\n        height:200,\n    },\n    center:{\n        justifyContent:&#039;center&#039;,\n        alignItems:&#039;center&#039;,\n    },\n});\n\nAppRegistry.registerComponent(&#039;RNAPP&#039;, () =&gt; RNAPP);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u5141\u8bb8\u5728\u5b50\u89c6\u56fe\u4e4b\u95f4\u5de6\u53f3\u7ffb\u9875\u7684\u5bb9\u5668\u3002\u6bcf\u4e00\u4e2aViewPagerAndroid\u7684\u5b50\u5bb9\u5668\u4f1a\u88ab\u89c6\u4f5c\u4e00\u4e2a\u5355\u72ec\u7684\u9875\uff0c\u5e76\u4e14\u4f1a [&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-493","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\/493","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=493"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/493\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}