相关疑难解决方法(0)

如何显示分页scrollView的当前页码?

滚动视图:

<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

5
推荐指数
2
解决办法
3753
查看次数

标签 统计

react-native ×1