【问题标题】:React native - ScrollView not working in androidReact native - ScrollView 在 android 中不起作用
【发布时间】:2021-08-12 15:54:27
【问题描述】:

我在 flex 中的 react-native 中使用了我的滚动视图,它可以在 web 上运行,但它不能在我的 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'
  }
});

【问题讨论】:

    标签: react-native flexbox scrollview


    【解决方案1】:

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

    更多关于contentContainerStyle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      • 2021-05-24
      相关资源
      最近更新 更多