[英]How to use ImageBackground to set background image for screen in react-native
[英]React Native Text inside ImageBackground wrapper is not displaying (With Image)
將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>
默認情況下, ImageBackground
帶有absoluteFill
樣式。
通過將position: 'relative'
設置為相對於 此處定義的視圖容器的image styles
。 因此,子元素將始終位於ImageBackground
解決方法是刪除樣式中的position: 'relative'
,並使用父容器style
對象。
作為ImageBackground styles={'//...View container styles'}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.