native base側(cè)邊篩選布局

react native 雖然有調(diào)樣式神器,但是用的樣式插件往往會滿足不了需求
以下使用native-base樣式組件,展示如何設(shè)置以下樣式



以下是樣式代碼

<View style={{flex: 1, marginRight: 10, alignItems: 'center', justifyContent: 'center'}}>
                <Button onPress={
                    this.selectFilterChildItem()
                } style={[{ height: 35, alignItems: 'center', justifyContent: 'center', alignSelf: 'stretch'},{backgroundColor: item.TypeName==='查看更多>' ? 'rgba(0, 0, 0, 0)' : '#f4f4f4' }]}>
                    <Text style={[{fontSize: 14, justifyContent: 'center', alignItems: 'center', paddingLeft: 0, alignSelf: 'center', paddingRight: 0},{color:item.TypeName==='查看更多>'?'#3393F2' : '#444444'}]}>{item.TypeName}</Text>
                </Button>
            </View>

這個是渲染Item的組件,父組件是FlatList
首先View的樣式

  • flex
  • marginRight
  • alignItems
  • justifyContent
    具體就是讓每個Item居中,并且有10的間隔

其次Button的樣式,核心代碼應(yīng)該是

  • alignSelf : 'stretch'
    讓每個Button的大小相等,調(diào)了很久才發(fā)現(xiàn)是這個樣式操作的
    stretch是指填充滿豎直方向上的空間,而此時用center是不能居中的

最后是Text的樣式,核心代碼應(yīng)該是

  • paddingLeft:0
  • paddingRight: 0
  • alignSelf: 'center'
    因?yàn)樽远x的左右邊距較寬,導(dǎo)致內(nèi)容顯示不全,于是設(shè)置padding控制左右邊距為0,再通過alignSelf進(jìn)行居中即可
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容