如何在本机反应中将scrollview拉伸到整个屏幕?

Zyg*_*gro 5 react-native

我有这个代码

render() {
  return (
    <View style={styles.container}>
      <TopMenu />
      <ScrollView style={styles.scrollView}>
        {array_with_two_items.map(this.createRow)}
      </ScrollView>
    </View>
  )
}
Run Code Online (Sandbox Code Playgroud)

与风格

scrollView: {
  flex:1,
  marginBottom:0,
},
containter: {
  flex:1,
},
Run Code Online (Sandbox Code Playgroud)

问题是它看起来像这样

+-----------+
|    MENU   |
+-----------+
|   item1   |
+-----------+
|   item2   |
+-----------+
|           |
|   blank   |
|    not    |
| scrollable|
+-----------+
Run Code Online (Sandbox Code Playgroud)

但我希望它看起来像

+-----------+
|    MENU   |
+-----------+
|   item1   |
+-----------+
|   item2   |
+-----------+
| blank,but |
|   still   |
|  part of  |
| scrollview|
+-----------+
Run Code Online (Sandbox Code Playgroud)

我对样式和flexbox的经验很少,所以这就是我要问的原因。(菜单不应该是滚动视图的一部分)

Tyl*_*ler 11

我想你想要的是flexGrow- flexGrow 文档

<ScrollView style={{ flex: 1 }} contentContainerStyle={{ flexGrow: 1 }}>
  
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢你的帮助,这让我免去了几天的痛苦和折磨 (3认同)

Aja*_*jay 9

只需将道具contentContainerStyle给 ScrollView ,如:

<ScrollView
   contentContainerStyle={{
     flex: 1
  }}
>
  /* Other Stuff */
</ScrollView>

Run Code Online (Sandbox Code Playgroud)