[英]React Native Text inside ImageBackground wrapper is not displaying (With Image)
The text in my imagebackground wrapper is not displayed when I set imageStyle position to relative. 将imageStyle位置设置为相对时,不会显示imagebackground包装器中的文本。
<TouchableWithoutFeedback style={{ position: 'relative', flex: 1, justifyContent: 'center' }} delayPressIn={500} onPressIn={() => this.onPressInMic()} onPressOut={() => this.onPressOutMic()}>
<ImageBackground imageStyle={{ position: 'relative', backgroundColor: 'transparent' }} source={this.state.micOn ? Images.micOn : Images.micOff} >
{
this.state.micOn
? (
<Text style={styles.micText}>PRESS TO{'\n'}STOP</Text>)
: (
<Text style={styles.micText}>PRESS TO{'\n'}RECORD</Text>
)
}
</ImageBackground>
</TouchableWithoutFeedback>
The text is supposed to be inside the image like 文字应该在图片内,例如
By default ImageBackground
comes with absoluteFill
style. 默认情况下, ImageBackground
带有absoluteFill
样式。
By setting position: 'relative'
, to the image styles
you're making it relative to the view container as defined here . 通过将position: 'relative'
设置为相对于 此处定义的视图容器的image styles
。 Therefore the children elements will always come below the ImageBackground
因此,子元素将始终位于ImageBackground
The workaround would be to remove the position: 'relative'
in the styles and use parent container style
object. 解决方法是删除样式中的position: 'relative'
,并使用父容器style
对象。
as ImageBackground styles={'//...View container styles'}
作为ImageBackground styles={'//...View container styles'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.