反应原生 - ScrollView 在 android 中不起作用

时间:2021-05-24 10:26:56

标签: react-native flexbox scrollview

我在 flex 内的 react-native 中使用了我的滚动视图,它可以在网络上运行,但在我的 android 手机上不起作用

这是我的代码-

  render() {
    return (
      <View style={styles.root}>
        <ScrollView contentContainerStyle={{flex: 1 }}>
          <View style={styles.box1} >
          </View>
          <View style={[styles.box2, { height: this.state.height }]} />
          <View style={styles.box1} >
               <TouchableOpacity onPress={() => this.setState({ height: this.state.height + 50 })}>
              <Text>Click me to grow the purple section</Text>
            </TouchableOpacity>
          </View>
        </ScrollView>
      </View>
    );
  }
}

这是我的样式表 -

const styles = StyleSheet.create({
  root: {
    flex: 1,
    flexDirection: 'column',
    backgroundColor: '#fff',
  },
  box1: {
    height: 200,
    backgroundColor: 'blue'
  },
  box2: {
    height: 200,
    backgroundColor: 'purple'
  }
});

1 个答案:

答案 0 :(得分:1)

尝试从 flex: 1 中删除属性 contentContainerStyle。如果需要 flex,您可以使用 flexGrow: 1 而不是 flex

有关 contentContainerStyle

的更多信息
相关问题