【问题标题】:Center search bar, justifyContent not working中心搜索栏,justifyContent 不起作用
【发布时间】:2021-04-20 02:48:08
【问题描述】:

我正在尝试使搜索栏在我的屏幕中居中。我正在使用 justifyContent 来尝试这样做。我总是可以使用填充来实现这一点,但我觉得我不应该这样做?我假设我错过了一些简单的东西。

我正在使用https://reactnativeelements.com/docs/searchbar/#containerstyle

非常感谢您的任何见解!

 <ScrollView style={{ flex: 1, backgroundColor: '#272933', }}>
<SearchBar
        placeholder="Search..."
        onChangeText={this.updateSearch}
        value={search}
        round='true'
        containerStyle={{marginTop: scale(15), backgroundColor: '#272933', borderBottomColor: 'transparent', borderTopColor: 'transparent', 
        display: 'flex', justifyContent: 'center'}}
        inputContainerStyle={{height: scale(30),  width: scale(200),justifyContent: 'center'}}
        searchIcon={() => <MaterialCommunityIcons name="glass-mug-variant" size={30} color='#87909A'/>}
        clearIcon= 'null'
      />

【问题讨论】:

    标签: css react-native


    【解决方案1】:

    justifyContent 适用于display:flex

    您也应该添加display: 'flex' 样式。

    【讨论】:

    • 我在上面的编辑中添加了它,我误解了什么?
    • 添加到containerStyle
    • 我试过了,也试过了,只在容器中,只在输入中,两者都有。
    • 仅供参考,您删除了justifyContent: center。添加后,用结果更新您的问题
    • 你能用inspect元素看到SearchBar父级的宽度吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-18
    • 2018-06-05
    • 2018-03-12
    相关资源
    最近更新 更多