滚动视图:
<View style={{flex:1}}>
<ScrollView
ref={(component) => {this._scrollView = component}}
scrollEventThrottle={15}
removeClippedSubviews={true}
pagingEnabled={true}
horizontal={true}
onScroll={this._onScroll.bind(this)}>
{items}
</ScrollView>
<Text style={styles.legend}>{this.state.currentPage}/{9}</Text
</View>
Run Code Online (Sandbox Code Playgroud)
_onScroll:这个方法计算当前页号是多少
<View style={{flex:1}}>
<ScrollView
ref={(component) => {this._scrollView = component}}
scrollEventThrottle={15}
removeClippedSubviews={true}
pagingEnabled={true}
horizontal={true}
onScroll={this._onScroll.bind(this)}>
{items}
</ScrollView>
<Text style={styles.legend}>{this.state.currentPage}/{9}</Text
</View>
Run Code Online (Sandbox Code Playgroud)
我认为代码行没问题,但是当我平移到scrollView下一页时,它会向后滚动。一旦我删除 中的代码行_onScroll,问题就可以解决,但我无法计算当前页码。
react-native ×1