react-native-swiper设定高度的方法(设置rn轮播图所占高度)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了react-native-swiper设定高度的方法(设置rn轮播图所占高度),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2672字,纯文字阅读大概需要4分钟。
内容图文
效果图:
直接上解决方案:
1、在Swiper标签外套一层View
<View style={styles.container}>
<Swiper
style={styles.wrapper}
height={width*40/75}
autoplayTimeout={2.5}
// showButtons —— 是否显示左右翻页按钮
showsButtons={false}
// autoPlay —— 是否自动播放
autoplay={true}
// paginationStyle —— 包含小点点的容器的样式,这里用来调整位置
paginationStyle={styles.paginationStyle}
// dotStyle —— 小点点的样式
dotStyle={styles.dotStyle}
// activeDotStyle —— 当前被激活的小点点的样式
activeDotStyle={styles.activeDotStyle}
>
<Image source={require(‘../img/mainSwiper/swiper1.jpg‘)} style={styles.bannerImg} />
<Image source={require(‘../img/mainSwiper/swiper2.jpg‘)} style={styles.bannerImg} />
<Image source={require(‘../img/mainSwiper/swiper3.jpg‘)} style={styles.bannerImg} />
</Swiper>
</View>
2、在View的style中设置高度
const styles = StyleSheet.create({
container: {
backgroundColor: "#f3f3f3" ,
height:width*40/75,
},
bannerImg: {
height: width*40/75,
width: width,
},
wrapper: {
width: width,
},
paginationStyle: {
},
dotStyle: {
width: 22,
height: 3,
backgroundColor:‘#fff‘,
opacity: 0.4,
borderRadius: 0,
},
activeDotStyle: {
width: 22,
height: 3,
backgroundColor:‘#fff‘,
borderRadius: 0,
},
});
3、注意style中不要使用flex。
4、完整版轮播图代码(下面即为MainSwiper.js的代码内容)
import React,{Component} from ‘react‘
import Swiper from ‘react-native-swiper‘;
import {
Image,
View,
StyleSheet,
Dimensions,
} from ‘react-native‘;
let {width} = Dimensions.get(‘window‘);
class MainSwiper extends Component{
render(){
return(
<View style={styles.container}>
<Swiper
style={styles.wrapper}
height={width*40/75}
autoplayTimeout={2.5}
// showButtons —— 是否显示左右翻页按钮
showsButtons={false}
// autoPlay —— 是否自动播放
autoplay={true}
// paginationStyle —— 包含小点点的容器的样式,这里用来调整位置
paginationStyle={styles.paginationStyle}
// dotStyle —— 小点点的样式
dotStyle={styles.dotStyle}
// activeDotStyle —— 当前被激活的小点点的样式
activeDotStyle={styles.activeDotStyle}
>
<Image source={require(‘../img/mainSwiper/swiper1.jpg‘)} style={styles.bannerImg} />
<Image source={require(‘../img/mainSwiper/swiper2.jpg‘)} style={styles.bannerImg} />
<Image source={require(‘../img/mainSwiper/swiper3.jpg‘)} style={styles.bannerImg} />
</Swiper>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: "#f3f3f3" ,
height:width*40/75,
},
bannerImg: {
height: width*40/75,
width: width,
},
wrapper: {
width: width,
},
paginationStyle: {
},
dotStyle: {
width: 22,
height: 3,
backgroundColor:‘#fff‘,
opacity: 0.4,
borderRadius: 0,
},
activeDotStyle: {
width: 22,
height: 3,
backgroundColor:‘#fff‘,
borderRadius: 0,
},
});
export default MainSwiper;
原文:https://www.cnblogs.com/piaobodewu/p/9888594.html
内容总结
以上是互联网集市为您收集整理的react-native-swiper设定高度的方法(设置rn轮播图所占高度)全部内容,希望文章能够帮你解决react-native-swiper设定高度的方法(设置rn轮播图所占高度)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。