首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-native-swiper图像不显示

react-native-swiper图像不显示
EN

Stack Overflow用户
提问于 2019-10-18 07:29:34
回答 1查看 312关注 0票数 0

我正在使用react原生swiper,无法看到我需要的照片。我把照片打错了吗?当我尝试使用Image标签像普通照片一样显示照片时,它可以工作,所以我知道我是从正确的目录导入照片。

代码语言:javascript
复制
....
import Swiper from 'react-native-swiper';
....
const ProfileCardScreen = ({navigation}) => {

  var profilePhotos=[{image:require('../images/NYE.jpg')},{image:require('../images/hiking.jpg')},{image:require('../images/baseball.jpg')}];

  return (
    <View style = {styles.container}>
        <Text style={styles.profilePageUserName}>User Name Here</Text>
        <Swiper showsButtons={true}>
            <View style={styles.slide1}>
                <Image style={{flex:1, height: undefined, width: undefined}}
                    resizeMode="contain"
                    source={require('../images/NYE.jpg')}/>
            </View>
            <View style={styles.slide2}>
                <Image style={{flex:1, height: undefined, width: undefined}}
                    resizeMode="contain"
                    source={require('../images/hiking.jpg')}/>    
            </View>
            <View style={styles.slide3}>
                <Image style={{flex:1, height: undefined, width: undefined}}
                    resizeMode="contain"
                    source={require('../images/baseball.jpg')}/>          
            </View>
        </Swiper>

EN

回答 1

Stack Overflow用户

发布于 2019-10-18 15:13:04

语法正确,请尝试在import语句中导入图像,如下所示

代码语言:javascript
复制
import Swiper from 'react-native-swiper';
import Image1 from '../images/NYE.jpg';
import Image2 from '../images/hiking.jpg';
import Image3 from '../images/baseball.jpg';
....
const ProfileCardScreen = ({navigation}) => {

var profilePhotos=[{image:require('../images/NYE.jpg')}, 
{image:require('../images/hiking.jpg')}, 
{image:require('../images/baseball.jpg')}];

 return (
<View style = {styles.container}>
    <Text style={styles.profilePageUserName}>User Name Here</Text>
    <Swiper showsButtons={true}>
        <View style={styles.slide1}>
            <Image style={{flex:1, height: undefined, width: undefined}}
                resizeMode="contain"
                source={Image1}/>
        </View>
        <View style={styles.slide2}>
            <Image style={{flex:1, height: undefined, width: undefined}}
                resizeMode="contain"
                source={Image2)}/>    
        </View>
        <View style={styles.slide3}>
            <Image style={{flex:1, height: undefined, width: undefined}}
                resizeMode="contain"
                source={Image3}/>          
        </View>
    </Swiper>

如果上面的代码也不能工作,那么一定是你的样式有问题。这就是我所能做的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58441973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档