javascript - 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.
<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>
解决方案
By default ImageBackground
comes with absoluteFill
style.
By setting position: 'relative'
, to the image styles
you're making it relative to the view container as defined here. Therefore the children elements will always come below the ImageBackground
The workaround would be to remove the position: 'relative'
in the styles and use parent container style
object.
as ImageBackground styles={'//...View container styles'}
推荐阅读
- ios - 如何计算从中心点到 UIView 上特定点的距离
- java - 当表 ID 具有虚拟列时,无法使用 JPA 进行插入
- python - 如何使用一个提交按钮在 django 中提交多个清晰的表单?
- winapi - 为什么 FindWindowEx 找不到工具提示类
- c# - 等待调用进入异常
- dataframe - 如果找不到元素,beautifulsoup 如何故意添加 return none
- php - 如何在recyclerview中显示为特定事件或项目注册的用户计数并在android的textview上显示?
- python - CS1301xl Computing in Python 我练习考试抵押问题的公式可能不正确?
- oauth-2.0 - IdentityServer4 JWT范围作为空格分隔的字符串而不是数组?
- flutter - 如何在飞镖/颤振中计算 GeoJson 几何区域