在标题react-native后面添加图像

时间:2018-10-10 05:33:00

标签: react-native react-native-android native-base react-native-swiper

我想用滑动器在标题后面添加多个图像。我尝试使用Native-basereact-native-swiper来实现。但是,结果如下。

enter image description here

以下是我的代码

<View style={{flex:1, elevation:2}}>
                    <Swiper style={StyleSheet.flatten( {backgroundColor: '#fff'})}>
                    <ImageBackground
                        source={require('../../img/auth_background.png')}
                        style={this.styles.backgroundStyle}
                        imageStyle={this.styles.backgroundImage}
                    >
                        <Header style={{
                            marginTop: StatusBar.currentHeight,
                            backgroundColor: 'transparent',
                            justifyContent: 'center',
                            alignItems: 'center',
                        }}>
                            <StatusBar
                                backgroundColor={Colors.statusBar}
                                barStyle="light-content"
                            />
                            <Left>
                                <Button transparent onPress={this.handleBackButtonClick} small={true}>
                                    <Icon name='ios-arrow-back' size={30} color={Colors.textWhite}/>
                                </Button>
                            </Left>
                            <Body/>
                            <Right/>
                        </Header>
                    </ImageBackground>
                        <ImageBackground
                            source={require('../../img/auth_background.png')}
                            style={this.styles.backgroundStyle}
                            imageStyle={this.styles.backgroundImage}
                        >
                            <Header style={{
                                marginTop: StatusBar.currentHeight,
                                backgroundColor: 'transparent',
                                justifyContent: 'center',
                                alignItems: 'center',
                                borderBottomWidth: 0, shadowOffset: {height: 0, width: 0},
                                shadowOpacity: 0, elevation: 0
                            }}>
                                <StatusBar
                                    backgroundColor={Colors.statusBar}
                                    barStyle="light-content"
                                />
                                <Left>
                                    <Button transparent onPress={this.handleBackButtonClick} small={true}>
                                        <Icon name='ios-arrow-back' size={30} color={Colors.textWhite}/>
                                    </Button>
                                </Left>
                                <Body/>
                                <Right/>
                            </Header>
                        </ImageBackground>
                    </Swiper>
</View>

我想修复标题,以便它也不会与图像滑动。谁能帮我这个?提前感谢。

3 个答案:

答案 0 :(得分:0)

未显示滑动器的高度和宽度时,Android中的React-Native-Swiper将显示空白内容。 请添加固定的高度和宽度以查看或滑动到

答案 1 :(得分:0)

将您的Header放在Swiper外面,并保持其位置absolute

<Header style={{
        marginTop: StatusBar.currentHeight,
        backgroundColor: 'transparent',
        justifyContent: 'center',
        alignItems: 'center',
        position:'absolute',
        top:0,
        left:0
}}>

答案 2 :(得分:0)

我找到了使用zIndexposition的解决方案。我想将基于本机的headercontainerzIndex一起使用时会出现一些问题。

<View style={{flex: 1}}>
                    <View style={{flex:1, zIndex: 2, position: 'absolute', marginTop: StatusBar.currentHeight, marginLeft:'2%'}}>
                       <Button iconLeft transparent>
                               <Icon name='ios-arrow-back' size={30} color={Colors.textWhite}/>
                       </Button>
                    </View>
                    <View style={{width: '100%', height: '50%', zIndex: 1, position: 'absolute'}}>
                        <Swiper style={StyleSheet.flatten( {backgroundColor: '#fff',zIndex:1, flex:1})}>
                            <ImageBackground
                                source={require('../../img/auth_background.png')}
                                style={this.styles.backgroundStyle}
                                imageStyle={this.styles.backgroundImage}
                            >

                            </ImageBackground>
                            <ImageBackground
                                source={require('../../img/auth_background.png')}
                                style={this.styles.backgroundStyle}
                                imageStyle={this.styles.backgroundImage}
                            >
                            </ImageBackground>
                        </Swiper>
                    </View>