【问题标题】:React native - Sliding background Images with some static content on topReact native - 顶部有一些静态内容的滑动背景图像
【发布时间】:2018-05-26 19:58:04
【问题描述】:

ImageBackground 需要一张图片,我能够添加具有图片和一些文本的子视图。但是,我想要的是像旋转图像一样的背景工作,而子视图保持原样反应本机。有没有办法做到这一点?

我现在拥有的:

<ImageBackground style= {styles.headerBackground} source={require('./img/headerBg.jpg')}>
    <View style={styles.top}>
        <Avatar
            small
            rounded
            icon={{name: 'menu'}}
            onPress={() => console.log("Works!")}
            activeOpacity={0.7}
        />               
    </View>
    <View style = {styles.header}>
        <Avatar
            large
            source={require('./img/profBg.jpg')}
            avatarStyle={{ borderWidth: 3, borderColor: 'white',  borderStyle:'solid' }}
            onPress={() => console.log("Works!")}
            activeOpacity={0.7}
        />
        <Text style={styles.name}>Name</Text>
        <Text style={styles.message}> Personal message</Text>
    </View>
</ImageBackground>

我不想在背景中使用一张图片,而是希望使用轮播/滑动图片。有人可以帮忙吗?

【问题讨论】:

    标签: android ios react-native imagebackground


    【解决方案1】:

    &lt;ImageBackground&gt; 只是一个&lt;View&gt;,里面有&lt;Image style={{position:'absolute'}} /&gt;。来源ImageBackground - https://github.com/facebook/react-native/blob/c6b96c0df789717d53ec520ad28ba0ae00db6ec2/Libraries/Image/ImageBackground.js#L63

    所以你可以做的是一样的,只是放多张图片,也许还有这样的父母:

    <View>
        <View style={{ position:'absolute' }}>
            <Image />
            <Image />
            <Image />
            <Image />
        </View>
    </View>
    

    【讨论】:

    • 谢谢。我还能让这个多图像视图中的子视图有一些静态文本吗?当图像在背景中滚动时,我希望有相同的文本。
    • 我不得不将 View 更改为 ScrollView 并让它工作!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    • 2014-01-06
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多