在 scrollView 滚动时同时滚动视图

scroll the view simultaneously as the scrollView scrolls

scrollPositionX: new Animated.Value(0),    

scrollEventThrottle={16}
onScroll={Animated.event([{nativeEvent: {contentOffset: {x: this.state.scrollPositionX}}}] )}

<Animated.View style={[styles.times, {
     transform: [{translateX: this.state.scrollPositionX}]
}]}>
   ...
</Animated.View>

此代码有效,但它会以相反的方向滚动动画视图。我如何让它向同一方向滚动。 这是关于这个问题 - React Native ScrollView Sticky View Element

使用interpolate:

<Animated.View style={[styles.times, {
  transform: [{
    translateX: this.state.scrollPositionX.interpolate({
      inputRange: [0, 1], 
      outputRange: [0, -1]
    })
  }]
}]}>