我正在尝试设置一个文本组件中的样式。就我在许多论坛上读到的,它不可能给它一个边距,宽度,高度。我基本上想要做的是得到这样的结果:
问题是,如果我将View组件中的所有内容都包装为父组件,图像也会在文本上方一点,我将无法对其进行样式设置。
任何帮助都将不胜感激!:)
发布于 2021-07-22 15:32:30
您可以按如下方式设置文本组件中的图像样式,并与您提供的图片中的样式相同
<Text> Hello I am
<Image
style={{ width: 30,
height: 30,}}
source={require('@expo/snack-static/react-native-logo.png')}
/>
{"Text after image" }
</Text>发布于 2021-07-22 16:17:15
为了对齐,你也可以这样做。
<View
style={{flexDirection: 'row',
alignItems: 'center', justifyContent:"center"
}}>
<Text> {"Text before image"}</Text>
<Image
style={{ width: 30, alignSelf:"center",
height: 30,}}
source={require('@expo/snack-static/react-native-logo.png')}
/>
<Text> {"Text after image" }</Text>
</View>结果如此link所示
发布于 2021-07-22 18:21:13
使用ImageBackground。
<Text> Hello I am
<ImageBackground>
style={{ width: 30,
height: 30,}}
source={require('@expo/snack-static/react-native-logo.png')}
resizeMode="cover" style={styles.image}>
<Text style={styles.text}>Inside</Text>
</ImageBackground>
{"Text after image" }
</Text>阅读docs
https://stackoverflow.com/questions/68480626
复制相似问题