【问题标题】:How to position component at bottom of screen如何在屏幕底部定位组件
【发布时间】:2018-05-21 00:58:05
【问题描述】:

我正在尝试将 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,
  },
 });

【问题讨论】:

    标签: react-native react-native-flexbox


    【解决方案1】:

      <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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多