Make an item stick to the bottom using flex in react-native

前端 未结 13 2363
别跟我提以往
别跟我提以往 2020-12-13 23:37

Suppose this is the layout:


    
        ...
        ...
    
             


        
13条回答
  •  别那么骄傲
    2020-12-14 00:30

    Consider a screen structure

    
       ... 
      ...
    
    

    You can do it cleanly using Flexbox approach utilizing flex-grow.

    const Styles = StyleSheet.create({
      container:{
        flexDirection: 'columm', // inner items will be added vertically
        flexGrow: 1,            // all the available vertical space will be occupied by it
        justifyContent: 'space-between' // will create the gutter between body and footer
      },
    
    })
    

    Note: In case of nested elements, you have to ensure that the parent container has enough height to work with when using flexGrow. Set backgroundColor on parents and child to debug.

提交回复
热议问题