react-native 实现微信头部编写

本文介绍了如何在react-native中实现微信头部,包括图标左右居右、上下居中的布局,以及点击事件处理,利用Flexbox进行布局,并通过TouchableHighlight实现点击背景色变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

react-native 编写微信头部要点:

   1、图标布局(左右居右、上下居中)

   2、可以点击事件,点击时有个背景色

布局实现

    1、在react-native中无法使用float、display:inline-block

    2、使用Flexbox(弹性盒子): flex, alignItems,justifyContent

本例通过Flexbox实现图标布局

header:{
height: height(150),
backgroundColor: '#373a3f',
paddingRight: width(70)
},
headerTools: {
flex: 1,
alignItems: 'center',
justifyContent: 'flex-end',
flexDirection: 'row'
},
headerIcon:{
alignItems: 'center',
justifyContent: 'center',
width: height(150),
height: height(150)
}

点击事件

    点击事件实现需要使用TouchableHighlight控件

<View style={style.header}>
<View style={style.headerTools}>
<TouchableHighlight onPress={this.search} >
<View style={style.headerIcon}>
<Search color={'#fff'}></Search>
</View>
</TouchableHighlight>
<TouchableHighlight onPress={this.create} >
<View style={style.headerIcon}>
<Add color={'#fff'}></Add>
</View>
</TouchableHighlight>
</View>
</View>

最终实现效果


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值