react-native中Text包含Image大小问题

转:https://www.jianshu.com/p/935a84956a32

react native版本: 0.52,

如果Text中包含Image,在样式中设置的width和height在安卓和苹果是完全不一样的。

可以使用下面的方法进行适配

import { PixelRatio } from 'react-native';

this.imageScale = Platform.OS === 'ios' ? 1 : PixelRatio.get();

在设置样式的时候

<Text>

<Image style={{width: width * this.imageScale, height: height * this.imageScale}} />

</ Text>


猜你喜欢

转载自blog.csdn.net/yeputi1015/article/details/80760936