React native how to wrap content view

前端 未结 4 1370
悲&欢浪女
悲&欢浪女 2021-02-03 21:25

I\'m pretty new with RN, is there anyway to wrap the content of the view, similar to Android. In Android I can adjust, Height: \'wrap-content\', but somehow in RN, I can\'t do a

相关标签:
4条回答
  • 2021-02-03 21:29

    If the content is vertical it should wrap by default; If the content is horizontal, things get tricky... What worked for me was putting the view container inside another view:

    <View style={{alignItems: "center"}}>
        <View style={{flexDirection: "row"}}>
            <Image/><Text/>
        </View>
    </View>
    
    0 讨论(0)
  • 2021-02-03 21:30

    You can set the parent to wrap child component like this.

    alignSelf: 'baseline'

    <View style={{ alignSelf:'baseline'}}>
      <Text>Child Content</Text>
    </View>
    

    Wrap child content horizontally.

    0 讨论(0)
  • 2021-02-03 21:36

    In the case of flexDirection: "row", you should use flexWrap: "wrap" to wrap the items inside.

    0 讨论(0)
  • 2021-02-03 21:51

    Views wrap their content by default if 'flex' attribute is not set.

    If you need the view to fill parent width or height set 'alignSelf' attribute to "stretch".

    0 讨论(0)
提交回复
热议问题