如何在屏幕底部定位组件

时间:2018-05-21 00:58:05

标签: react-native react-native-flexbox

我试图将SegmentedControlIOS组件定位到屏幕底部:

return (
  <View style={styles.container}>
    <Button title="toggle names" onPress={this.toggleContacts}  />
    <Button title="sort" onPress={this.sort}  />
    <Button title="New contact" onPress={this.toggleForm}  />

    { this.state.showForm &&
      <AddContactForm
        addContact={this.addContact}/>
    }
    {this.state.show && this.state.selectedIndex === 0 &&
      <ScrollView >
        {this.state.contacts.map(contact=>(
          <Row  {...contact}/> ))}
      </ScrollView>}
    {this.state.show && this.state.selectedIndex === 1 &&
      <FlatList
        data={this.state.contacts}
        keyExtractor = { (item, index) => index.toString() }
        renderItem={renderItem}>
      </FlatList>}
    {this.state.show && this.state.selectedIndex === 2 &&
      <ContactsList
        contacts={this.state.contacts}>
      </ContactsList>}
    <View flex bottom style={{flex:1,}}>
      <SegmentedControlIOS
        values={['ScrollView', 'FlatList','SectionList']}
        selectedIndex={this.state.selectedIndex}
        onChange={(event) => {
          this.setState({selectedIndex: event.nativeEvent.selectedSegmentIndex});
        }} />
      </View>
  </View>
)
}
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    // alignItems: 'flex-start',
    paddingTop: Constants.statusBarHeight + 25,

  },
  row: {
    padding:20,
  },
  input: {
    padding:5,

    borderColor:'black',
    borderWidth:1,
  },
 });

1 个答案:

答案 0 :(得分:0)

  <View  style={{flex:1,justifyContent:'flex-end',marginBottom:20}}>
          <SegmentedControlIOS
            values={['ScrollView', 'FlatList','SectionList']}
            selectedIndex={this.state.selectedIndex}
            onChange={(event) => {
              this.setState({selectedIndex: event.nativeEvent.selectedSegmentIndex});
            }} />
          </View>