React Native: vertical centering when using ScrollView

前端 未结 6 578
孤街浪徒
孤街浪徒 2021-01-30 12:28

I\'m using React Native and I\'m having trouble retaining vertical centering of elements as soon as I introduce a ScrollView. To demonstrate, I created 3 apps with React Native

6条回答
  •  没有蜡笔的小新
    2021-01-30 13:02

    Here is my approach:

    Use an outer container with flex : 1, then the scroll view needs to have {flexGrow : 1, justifyContent : 'center'} using contentContainerStyle, not style.

    
      
          
            //Put your stuff here, and it will be centered vertical
          
      
     
    

    Styles:

    const styles = StyleSheet.create({scrollView : {
    height : Dimensions.get('window').height, }, mainContainer : {
    flex : 1 }, scrollViewContainer : { }, })
    

提交回复
热议问题